Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BMP Entity bean primary key

 
rastin purr
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
rastin purr
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 17989
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
rastin purr
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic