-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Generating an account number based on the id
PostPosted: Thu Jun 19, 2008 1:29 am 
Newbie

Joined: Thu Jun 19, 2008 1:05 am
Posts: 1
Hi. I don't account numbers that are to be seen by clients to be exactly the same as the given sequential id so I want to have another field that contains the id with some appended random numbers. But I don't know the id until I have saved the object to the database. After I have saved the object the then detached object contains the id and then I can make the new field. But then I can't declare that field as non-null which I would think would be pretty important. Also I have to make two hits to the database for one save.

Is there a better way to do this?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 23, 2008 10:44 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
The save method returns the primary key, even before the transaction is comitted. You can get the primary key that is about to be used, and set your other properties, and then do the commit. You'll only end up with one transaction through one Hibernate Session.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.