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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:55:31+00:00 2026-05-14T19:55:31+00:00

Given example from Hibernate docs and modifying it so that root level entity (Customer)

  • 0

Given example from Hibernate docs and modifying it so that root level entity (Customer) is read-only while one of its collections (tickets) is read-write:

@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class Customer { 
    ... 
    @OneToMany(...)
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    public SortedSet<Ticket> getTickets() {
        return tickets;
    }
    ...
}

Would collection of tickets get refreshed when accessing customer from cache?

  • 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-14T19:55:32+00:00Added an answer on May 14, 2026 at 7:55 pm

    If you modify one of the tickets of a given Customer somewhere else, yes. Why don’t you test this? Let’s assume Cutomer#1 has Ticket#1 and Ticket#2 in its tickets collection. I ran this code:

    // loading in first session
    Session session1 = HibernateUtil.getSession();
    Transaction tx1 = session1.beginTransaction();
    Customer c1 = (Customer) session1.load(Customer.class, 1L); // loads from db and puts in cache
    for (Ticket ticket : c1.getTickets()) { // caches q2742145.Customer.tickets#1
        System.out.println(ticket);
    }
    Ticket ticket = (Ticket) session1.load(Ticket.class, 1L); // doesn't hit the db
    ticket.setName("foo"); // do some change on Ticket#1
    session1.save(ticket);
    tx1.commit(); // Ticket#1 gets updated in the db and the cached association invalidated
    
    // loading in second session
    Session session2 = HibernateUtil.getSession();
    Transaction tx2 = session2.beginTransaction();
    Customer c2 = (Customer) session2.load(Customer.class, 1L); // hits the cache
    Set<Ticket> tickets = c2.getTickets();
    for (Ticket ticket2 : tickets) { // reloads tickets from db
        System.out.println(ticket2); 
    }
    tx2.commit();
    

    Which shows the collection of tickets gets “refreshed”.

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

Sidebar

Related Questions

Going from the example given here... http://ericswann.org/blog/archive/2009/04/06/linq-to-sql-datacontext-provider-revisited.aspx I'm trying to use the datacontext between
Given the XML/RDF example below taken from the W3C website, how can I access
Could you guys give me an example how to read and write from/to xml
I need a regex that will give me the following results from each example
I am trying to create a query using hibernate following the example given in
Given a query for example: from Users u where u.Country = US I have
Can hibernate resolve mapping across more than one table. Here is example: Class Manufacturer,
Everything I read about Hibernate states that you must roll back a transaction and
Given the following code example from MSDN: private void GetPixel_Example(PaintEventArgs e) { // Create
Given the typical nested model example from Railscasts: http://railscasts.com/episodes/196-nested-model-form-part-1 How would you associate the

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.