-->
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.  [ 5 posts ] 
Author Message
 Post subject: PK generation before save()
PostPosted: Fri Nov 21, 2003 8:51 am 
Beginner
Beginner

Joined: Thu Oct 30, 2003 6:29 am
Posts: 30
Location: Germany, KA
hi,

i'd like to generate an id for a persisten object before calling the save() method. Is it possible to use the hibernate generator or do I have to generate my own id and set it manually?

thanks alot
marie


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 8:52 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I don't quite understand. Please explain your usecase a bit better....


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 9:03 am 
Senior
Senior

Joined: Tue Sep 23, 2003 8:18 am
Posts: 137
Location: Johannesburg, South Africa
If you generate your own PK via some algorythm then you would use the ASSIGNED generator. Alternatively, you can use one of the various generators that Hibernate makes use of.

-G


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 9:07 am 
Beginner
Beginner

Joined: Thu Oct 30, 2003 6:29 am
Posts: 30
Location: Germany, KA
i am instanciating an empty entity that is to be saved to db later. but i want to use the id of this entity in the constructor of this persistent class. when using the generator of hibernate the id is generated when saving the entity to db, but this should be done later and not in the constructor. so i want to access/generate the id BEFORE calling save() the first time.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 7:04 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Marie wrote:
so i want to access/generate the id BEFORE calling save() the first time.

Hibernate does not know about your object since you save it, so it cannot generate the id before saving it.
Remember that session.save() does not execute the insert statement. It will be done during session flush.

If you must have an id before applying session.save, then you need to generate it manually and assigned iy by object.setMyObjectId(...).

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.