• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

BMP Entity bean primary key

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic