HQL updates and domain objects

Posted by CaptainAwesomePants on Stack Overflow See other posts from Stack Overflow or by CaptainAwesomePants
Published on 2010-03-19T17:39:18Z Indexed on 2010/03/19 17:41 UTC
Read the original article Hit count: 266

Filed under:

I have what may be a pretty elementary Hibernate question. Do HQL (and/or Criteria) update queries cause updates to live domain objects? And do they automatically flush now-invalid domain objects from the first-level cache?

Example:

Player playerReference1 = session.get(Player.class,1);
session.createQuery("update players set gold = 100").executeUpdate();
//Question #1 -- does playerReference1.getGold() now return 100?
Player playerReference2 = session.get(Player.class,1);
//Question #2 -- does playerReference2.getGold() return 100, or is it the same exact object?

Should I make a practice of evicting all objects that are affected by an HQL update if there's a chance some code will need it later?

© Stack Overflow or respective owner

Related posts about hibernate