| Author |
Handling in memory objects with autogenrated key
|
sameer sood
Ranch Hand
Joined: Dec 05, 2007
Posts: 30
|
|
Hi i am facing a problem when working with Hibernate It is like this Say i have an object mapped class mappedClass which is in memory The table to which it is mapped is having an auto generated key element So the problem occurs here i have an ArrayList of objects in memory i apply them to the database The in memory don't get auto generated keys from database so how to make this happen as my page requires this objects to be reeddited like save and continue editing thing???
|
Sameer Sood
SCJP 1.5 (93%), SCWCD 1.5 (95%)
|
 |
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Joined: Aug 26, 2006
Posts: 4967
|
|
When you say 'in memory', do you mean stored as an instance variable in your program, or stored in the cache of the Hibernate Session. I'm guessing it's the former. If these are persistent objects, why not use the Hibernate cache, and not duplicate the caching in your program. Just pull the properties out of Hibernate directly, rather than performing a double cache. You'll get the most up to date values, and you won't have problems finding the primary key! -Cameron McKenzie
|
Author of Hibernate Made Easy, What is WebSphere???, JSF 2.0 Made Easy and the SCJA Certification Guides
|
 |
sameer sood
Ranch Hand
Joined: Dec 05, 2007
Posts: 30
|
|
|
I did a workout of my own on this but i have no idea about hibernate cache
|
 |
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Joined: Aug 26, 2006
Posts: 4967
|
|
Don't get too intimidated by the term 'cache.' It's just the objects that the Hibernate Session has 'touched' or used while a transaction is in the works, and as such, the Session has a copy of it. It maintains this copy in memory, and maintains any updates that happen to the object. Then, when the transaction commits, all the objects in the cache have their final state persisted to the database. Here's a little tutorial on the topic of how Hibernate and the Hibernate Session works: How Hibernate Works: From Transient Objects to the Hibernate Cache Happy Hibernating! -Cameron McKenzie
|
 |
sameer sood
Ranch Hand
Joined: Dec 05, 2007
Posts: 30
|
|
Been Hibernating a lot seem to have got some hold if it updating auto generated keys gave pains too But finally i am able to do all that thanks for the quick replies
|
 |
 |
|
|
subject: Handling in memory objects with autogenrated key
|
|
|