Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

CMP beans - id

Thread view: 
Demetz Markus - 07 Dec 2005 10:17 GMT
Hi everybody!

I'm new to CMP Beans, and i want each bean to have a unique id and do the
relationships over id's. But which is the best way to generate id's? I found
the following:

private Integer generatePrimaryKey() {
 return new Integer((new Object()).hashCode());
}
is this a good way?
Isn't there another approach to do an autoincrement?

Thanks for any hint!
Markus
Viator - 07 Dec 2005 13:30 GMT
There is no guarantee that new Object().hashCode() will always give you
unique numbers. Try using a class (some sort of Sequencer) that gives
you a unique integer and increments it by one with every call.

Amit :-)
Bjoern Bredohl - 07 Dec 2005 14:47 GMT
Demetz Markus schrieb:
>  private Integer generatePrimaryKey() {
>   return new Integer((new Object()).hashCode());
>  }
You can use this in jdk 1.5.x
...
setId(java.util.UUID.randomUUID().toString());
...

You can also look for UUID Generator like JUG (http://jug.safehaus.org/Home)

> Isn't there another approach to do an autoincrement?
Yes, there is another possibility. The RDB can autoincrement. But if you
have CMR's you get problems.

Björn


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.