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 3991950
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:40:37+00:00 2026-05-20T06:40:37+00:00

I have Hibernate with 2nd level cache provided by Ehcache. I have Parent and

  • 0

I have Hibernate with 2nd level cache provided by Ehcache.

I have Parent and Child classes, with Parent.children cached collection.

When I execute the following code:

Session session = DataSessionFactory.openSession();
Transaction tx = session.beginTransaction();
Parent parent = // load from Session
Child child = new Child();
child.setParent(parent);
session.saveOrUpdate(child);
session.flush();
session.refresh(parent);
tx.rollback();
session.close();

session = DataSessionFactory.openSession();
tx = session.beginTransaction();
parent = session.load(Parent.class, parent.getId());
System.out.println(parent.getChildren());

The last line fails with an exception, trying to load Child which does not exist. After investigation I found the reason is that it’s trying to load Child which have been created and rolled back in the previous transaction.

What is the correct way to configure caching, or roll back the transaction, so that collection cache is cleared properly? I don’t want to purge all collection caches on rollback, thank you. Looking for a way to make Hibernate or Ehcache do it for me with minimal impact.

  • 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-05-20T06:40:38+00:00Added an answer on May 20, 2026 at 6:40 am

    The Hibernate transaction manager is quite simple and from what you described, it seems it doesn’t handle this case. The reason is simple: Hibernate is not trying to implement JTA by itself, as there are plenty of JTA providers out there. So, if you are using an application server like JBoss AS, you can configure Hibernate and EHCache to use its JTA provider, which would certainly handle this situation.

    Also, I believe that the entity is being put into the cache by the “flush” method. So, if you don’t want to use a JTA provider and unless this “flush” is really needed, I’d remove that part.

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

Sidebar

Related Questions

We have an application that uses Hibernate's 2nd level caching to avoid database hits.
We can speed up a hibernate app easyly with 2nd level cache using infinispan
we have a website that uses nhibernate and 2nd level cache. We are having
I have enabled 2nd level cache in FluentNHibernate: Fluently.Configure() .Database(MsSqlConfiguration.MsSql2005 .ConnectionString(connectionString) .Cache(c => c.ProviderClass<SysCacheProvider>().UseQueryCache())
We have a Hibernate/Spring application that have the following Spring beans: <bean id=transactionManager class=org.springframework.orm.hibernate3.HibernateTransactionManager
I am just doing some experiments on Castle AR and 2nd level cache of
We have hibernate-based system and customer wants to get human-readable names of PK and
We have an object, A, which contains another object, B. We have Hibernate calling
I have one hibernate sequence, that generates all sequence-numbers in my app. When I
I have a hibernate mapping as follows: <hibernate-mapping> <class name=kochman.elie.data.types.InvoiceTVO table=INVOICE> <id name=id column=ID>

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.