Maybe I am wrong, but from my view, I do not see a solution of this. I think it would be the easiest way to implement a stateless SB that calls executes some SQL in a TX=RequiresNew method. If it is set to TX=RequiresNew, you are sure that the transaction ends after the call and with that, the database is synchronized to the new high water mark you calculated in the SQL.
 
Maybe in EJB 2.0 you could solve this with Home interfaces, but JOnAS does not provide this feature yet.
 
I'm also not quite sure if DBMS-generated values are target of the EJB spec, since EJB intents to have all work done in beans.
 
Markus
 
 
Original Message      
 processed by Tobit InfoCenter 
Subject: 
Auto-increment primary keys for beans with CMP (24-Aug-2001 10:12)
From:    
[EMAIL PROTECTED]
To:      
[EMAIL PROTECTED]
 
Hi,
 
I've written a simple Entity Bean with CMP which has a primary key of type int.
In the database (Oracle), I have set a trigger to auto-increment the primary key attribute mapping the primary key field of the CMP Bean, each time a row is created in the table.
When calling the ejbCreate method I get an exception :
 
javax.ejb.EJBException: Failed to load bean from database
javax.ejb.EJBException
java.rmi.RemoteException: Got exception in activate:; nested exception is:
        javax.ejb.EJBException
 null EJBContext in RequestCtx!
 System Exception raised by request:
java.rmi.RemoteException: Got exception in activate:; nested exception is:
        javax.ejb.EJBException
 System Exception in business method:java.rmi.RemoteException: Got exception in activate:; nested exception is:
        javax.ejb.EJBException
I have searched on the mailing list some solutions to get the primary key to increment automatically, but all of them are quite not suitable :
- the solution of doing a "SELECT(MAX)" on the primary key, proposed by Joe on page http://www.objectweb.org/messages/JonasUsers/2000/03/msg00020.html, is not reliable due to parallel acces to the database, and wouldn't match the CMP favour wich is not to include JDBC in the java code.
- the solution of Guillaume (http://www.objectweb.org/messages/JonasUsers/2000/04/msg00085.html) which is to implement 2 EJB is a pretty heavy one and also needs some BMP to be written.
 
So here is my question (which maybe you already have guessed) : Is there a way for the primary key of an Entity Bean with CMP to be auto-incremented without writting some JDBC code ?
 
I couldn't find a real answer on the JOnAS mailing list and I would simply like to know if it's possible or not (and of course, if it's possible, the way to do it). It seems I'm not the only one having this problem, so I think it should be sayed once for all at least one time on the mailing list or the FAQ...
 
Thanks
 
                                Thomas
To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED]

Reply via email to