Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8858005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:43:38+00:00 2026-06-14T14:43:38+00:00

I am using Hibernate (4.1.8.FINAL), MySQL (InnoDB) and I am experiencing a problem with

  • 0

I am using Hibernate (4.1.8.FINAL), MySQL (InnoDB) and I am experiencing a problem with saving multiple entities.

According to Hibernate documentation http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html/ch15.html the batch processing should be supported, but I am getting following exception:

org.hibernate.TransactionException: nested transactions not supported
    at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:152)
    at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1395)
    ...

Here’s the code I wrote (Class EntryDaoImpl.java):

@Transaction
public void saveAll(final Collection<T> entities) {
    if (CollectionUtils.isEmpty(entities)) {
        return;
    }
    final Session session = this.sessionFactory.getCurrentSession();
    Transaction tx = null;
    try {
        tx = session.beginTransaction();
        for (final T entity : entities) {
            session.saveOrUpdate(entity);
        }
        tx.commit();
    } catch (final RuntimeException e) {
        if (tx != null) {
            tx.rollback();
        }
        throw e;
    } finally {
        session.flush();
        session.clear();
    }
}

And here is the JUnit method:

@Test
public void deleteAddress() {
    Entry entry;
    // Entry 2 has three addresses (delete all those)
    entry = this.entryDao.findById(2);
    Assert.assertEquals(3, entry.getAddresses().size());
    entry.setAddresses(null);
    this.entryDao.saveAll(Collections.singleton(entry));
}

The exception also occurs if only one entity will be updated. I also tried with openSession() instead of getCurrentSession() but the exception would be following:

org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
    at org.hibernate.collection.internal.AbstractPersistentCollection.setCurrentSession(AbstractPersistentCollection.java:638)
    at org.hibernate.event.internal.OnUpdateVisitor.processCollection(OnUpdateVisitor.java:65) 

If I go without transaction logic then it works. During research with search engine I see many developers told that Hibernate doesn’t support transaction at all. Not sure if this statement is outdated. confused

So my question is: does Hibernate supports transaction (as described in documentation)? And/or can you tell me what is wrong with my code? Thank you 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:43:39+00:00Added an answer on June 14, 2026 at 2:43 pm

    You are using both declarative transaction (@Transaction) as well as programatic transaction.

    tx = session.beginTransaction();
    for (final T entity : entities) {
        session.saveOrUpdate(entity);
    }
    tx.commit();
    

    Since you are using both the transaction in the same code, Hibernate complains

    org.hibernate.TransactionException: nested transactions not supported
    

    Remove your Transaction annotation at the top of your class and it should work, else remove your beginTransaction and commit.

    Hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with Hibernate (3.6.0.-Final) in my Java EE application using MySQL
I'm using Hibernate 4.0.1.Final and MySQL 5.1. My domain object contains a java.util.Calendar object
We are using Hibernate 3.6.1.FINAL against Oracle 11g . We are experiencing blocking locks
Using hibernate @Any mapping to map multiple entities in the same, I haven't be
I'am using Hibernate framework 3.6.10.Final and MySql. I'am getting Exception in thread main org.hibernate.MappingException:
I am using Hibernate 3.6.0 with JPA 2 on Jboss AS 6.0.0 final. In
I'm using Spring 3.1.0.RELEASE, Hibernate 4.0.1.Final, and MySQL 5.1. What is the pooled data
I'm using Hibernate 4.0.1.Final with a MySQL 5.5 database. I'm writing a Java console
I am using Hibernate 3.6.8.Final as part of a project deployed in JBoss 4.3
I'm using Hibernate 4.1.0.Final and hibernate-jpa-2.0-api. I'm having a problem using an entity manager

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.