File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes the best way to generate the primary key for entity bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "the best way to generate the primary key for entity bean" Watch "the best way to generate the primary key for entity bean" New topic
Author

the best way to generate the primary key for entity bean

zb cong
Ranch Hand

Joined: Jan 14, 2002
Posts: 416
hello
i am the beginner to entity bean,and usually use the toplink as the o-r mapping tool.it can generate the unique primary key automatically for me,i don't need to worry about it.
now i transfer to entity bean,i found that i must generate the pk in my code(if i use the integer id as primary key),then invoke the "create" method to insert a record to database,but how can i keep the id unique?
who can introduce me the best mechanism to generate pk for the entity bean?
thank you very much!
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
http://www.theserverside.com//patterns/thread.jsp?thread_id=4228
http://www-106.ibm.com/developerworks/java/library/j-ejbdesign.html


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Have a look at EJB design patterns, by floyd marinescu.
You can find a free PDF copy of the book at www.theserverside.com. It's got different patterns on how to generate keys.


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: the best way to generate the primary key for entity bean
 
Similar Threads
Primary Key class
ID Generator
Question about sequences and entity ejbs 3.0
Concatenated Primary Key For CMP With CMR
entity bean for a table with No Primary key : Please Help,,,, URGENT