Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Handling in memory objects with autogenrated key

 
sameer sood
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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???
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
sameer sood
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic