newbie hibernate first level cache confusion
Posted
by Bruce
on Stack Overflow
See other posts from Stack Overflow
or by Bruce
Published on 2010-05-27T14:20:04Z
Indexed on
2010/05/27
14:21 UTC
Read the original article
Hit count: 196
hibernate
Hi all I'm just geting to grips with hibernate. Little bit confused.
I just wanted to watch the operation of the first level cache, which I understood to batch up queries until the end of the session.
But if I create an object, hibernate saves it immediately, so that when I later update it in the same transaction, it has to do an update too:
Session session = factory.getCurrentSession();
session.beginTransaction();
Test1 test1 = new Test1();
test1.setName("Test 1");
test1.setValue(10);
// Touch it
session.save(test1);
System.out.println("At checkpoint 1");
test1.setValue(20);
session.getTransaction().commit();
I see the sql for the save, then 'At checkpoint 1', then the sql for the update. Do I have something set up wrong or am I misunderstanding hibernate's first level cache? Is there a good document on the first level cache - I didn't find anything in the hibernate docs, but I could easily have missed it..
Thanks!
© Stack Overflow or respective owner