GeeCON Prague 2014*
The moose likes EJB and other Java EE Technologies and the fly likes BMP Entity bean primary key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "BMP Entity bean primary key" Watch "BMP Entity bean primary key" New topic
Author

BMP Entity bean primary key

rastin purr
Ranch Hand

Joined: Jul 20, 2002
Posts: 73
Hi all,
I've a table in database got trigger so the primary key will increment before insert statement.
I have a BMP entity bean. In the ejbCreate method, i need to return a primary key. But as it is done by the trigger, how can i get it? Any advice is needed. Thanks.
Is Calendar.getInstance().getTimeInMillis() unique? Please advice. Thanks again
Rastin
Jes Sie
Ranch Hand

Joined: Jul 24, 2001
Posts: 188
Originally posted by rastin purr:
Hi all,
I've a table in database got trigger so the primary key will increment before insert statement.
I have a BMP entity bean. In the ejbCreate method, i need to return a primary key. But as it is done by the trigger, how can i get it? Any advice is needed. Thanks.
Is Calendar.getInstance().getTimeInMillis() unique? Please advice. Thanks again
Rastin

Have a look at the unique key Design Patterns by from here http://www.theserverside.com/books/EJBDesignPatterns/index.jsp . The PDF tells 2 good unique key generators but you may sacrifice on some performance.


Thank you.<br /> <br />- Jess Sie<br /> <a href="mailto:jess@see-consulting.com" rel="nofollow">jess@see-consulting.com</a>
rastin purr
Ranch Hand

Joined: Jul 20, 2002
Posts: 73
Thanks Simon,
is there any other way around it?
Is Calendar.getInstance().getTimeInMillis() good enough to be the primary key? or some database specific command that return the primary key?
All views are very much apprecited .Thanks guys
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16091
    
  21

Some OS's have a timer function that guarantees no 2 calls will return the same value, but for the rest of us, there's always that miniscule chance of a collision.
I just keep a keymanager EJB that has a "dispenseKey" method. Since it's an EJB, transaction management and atomicity ensure that each call can be made to return a unique value, and also, since it's an EJB, the more you need it, the more often you'll find it in cache.


Customer surveys are for companies who didn't pay proper attention to begin with.
rastin purr
Ranch Hand

Joined: Jul 20, 2002
Posts: 73
Tim,
Thanks. I think the best way is to do as you previously said. Thanks!
Tim, is there no way that could read in the trigger value?
Ras
 
GeeCON Prague 2014
 
subject: BMP Entity bean primary key