-->
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.  [ 6 posts ] 
Author Message
 Post subject: Retrieve next identifier for component
PostPosted: Thu Apr 29, 2004 4:56 am 
Beginner
Beginner

Joined: Fri Apr 02, 2004 1:20 pm
Posts: 23
I recently raised a feature request which was closed:

http://opensource.atlassian.com/project ... wse/HB-924

Can anyone shed any light on Gavin's comment that there "are other ways to do this"?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 30, 2004 12:58 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Why don't you write you own IdentifierGenerator.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 01, 2004 1:46 pm 
Beginner
Beginner

Joined: Fri Apr 02, 2004 1:20 pm
Posts: 23
Because the one that comes with Hibernate works perfectly!

I want to get access to a valid newly generated ID so I can derive some property values from it.

I'd imaging there would be other useful applications of

Serializable Session.generateIdentifier(Class component);


Regards,

Niall


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 7:08 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
niallsmart wrote:
I'd imaging there would be other useful applications of
Serializable Session.generateIdentifier(Class component);

I thought about that and the best solutions I came to were:
- use a custom generator if the ID is a CONSTANT + Unique Id
- build the property in a plain getter if the property is build on top of the id.

Session.getIdentifier(Class) is not really OO

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 21, 2004 2:23 pm 
Beginner
Beginner

Joined: Fri Apr 02, 2004 1:20 pm
Posts: 23
Not OO? In what way? Perhaps you would be happier with this?

Session.getIdentifierGenerator(Class);

In any case I worked around this limitation by subclassing IncrementGenerator.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 25, 2007 9:19 am 
Newbie

Joined: Wed Apr 25, 2007 9:10 am
Posts: 1
For some reason nobody wants to give a straight answer to this question :).
The real reason is that the getIdentifierGenerator(...).generate(...) needn't
always give the id. For e.g. in MySQL, if generator class is native and
autoincrement is set on the table's primary key following is what hibernate would do
1/ insert the row without setting the id
2/ use MySQL's last_insert_id() function to reterive the id of the row that
was just inserted
3/ set this id on the object and return the id

In such a scenario calls to getIdentifierGenerator(...).generate(...) before inserting a row would return nothing!


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