-
1. Re: CMP 2.0 & PK Generation
dsundstrom Dec 3, 2001 1:44 PM (in response to ceolter)Nope. It is on the todo.
-dain -
2. Re: CMP 2.0 & PK Generation
sealbb Dec 5, 2001 1:45 AM (in response to ceolter)build a entitybean with fields:
- itemName
- counter
to serves as a counter ...
or do this (may cause problems when machine switch datetime setting):
public class IdGenerator
{
private static long t = System.currentTimeMillis();
synchronized
public static long getNextId()
{
return long++;
}
} -
3. Re: CMP 2.0 & PK Generation
dsundstrom Dec 5, 2001 4:40 PM (in response to ceolter)I would highly recommend NOT using this technique.
-
4. Re: CMP 2.0 & PK Generation
jhicks Dec 6, 2001 1:56 PM (in response to ceolter)There are several ways to do PK generation for CMP beans. There are several patterns posted at theserverside.com for PK generation. Look at http://www.theserverside.com/resources/patterns_review.jsp for a pattern. Floyd Marinescu lists several different ways to accomplish PK generation.
James Hicks -
5. Re: CMP 2.0 & PK Generation
steinarc Dec 12, 2001 3:20 AM (in response to ceolter)If your Entity bean utilises Bean Managed Persistence, you can use the mySQL proprietary method "getLastInsertID()".
I don't know about mySQL 4.0, but in version 3.23 this method only exists in the "Statement" class, so you need to do some casting to make it work, furthermore you must ensure that you use the getUnderlyingPreparedStatement() to get the statement on which you are going to call getLastInsertID().
Meanwhile, if you have figured out something smarter, please let us know, I for one would be very interested. -
6. Re: CMP 2.0 & PK Generation
ceolter Dec 12, 2001 4:14 AM (in response to ceolter)thanks for advice, if jboss doesn't provide pk generation than i'll be using a variation of the sequence pattern described in theserverside,
http://www.theserverside.com/resources/review/ejbpatterns-primarykeystrategies-sept3.zip
tnks,