Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate: save and retrieve immediately

 
Mohit Sinha
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I have a particular requirement where in I need to insert data into a table via Hibernate and fetch it back immediately. Typically (correct me if I am wrong) in Hibernate there is 1 operation for insert and then a subsequent operation for fetch. I want to somehow chain these 2 operations into one transaction such that the session which inserts the record gets its record back and not of some other operator's session.
currently I am inserting one record and then based on a query which picks the latest record fetch the data back. This works fine in a single user model but when simultaneous users start using this application I want to avoid users getting wrong data.
example) I enter a record for policyname='sss' and version='1'.in the database a unique id is attached for this run (say runid=22). I need this data back.
Now multiple users can work on the same policyname='sss' and version='1' at the same time so its quiet possible the runid they get may be not the appropriate ones.
Do post your thoughts on the same.
 
Janus Engstrøm
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mohit,

It's not possible to change the way you retrieve the inserted row? Currently, you're fetching the just inserted row by selecting the row with the highest roleID, right? When you persist your data, the runID field is automatically set by Hibernate, so you can retrieve the row by that ID:



Regards,

Janus
 
k.siva prasadreddy
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If you want to get the saved object immediately you can use session.merge(object), which returns the inserted objected.

Thanks,
K. Siva Prasad Reddy.
 
Mohit Sinha
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Janus/Siva

Thanks for your suggestions. With regards to the runid in this case is being inserted by an ORacle sequence in the backend.

Regards
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic