![]() |
|
|
|
#1 |
|
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 Demetz Markus |
|
|
|
|
#2 |
|
Posts: n/a
|
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 Viator |
|
|
|
#3 |
|
Posts: n/a
|
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 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (MingW32) Comment: GnuPT 2.7.2 iD8DBQFDlvX2BI/akcB2BtkRAu+fAJ4zFvTXbW/6L+jITfpuaQjz0hiL0QCfcwe9 55HGDkmJ4ZmSK6B2TpWn96o= =L/0n -----END PGP SIGNATURE----- Bjoern Bredohl |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Scarface - widescreen version easily missed | JWB | DVD Video | 28 | 10-09-2003 09:48 PM |