aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Help on CMP for J2EE-RI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Help on CMP for J2EE-RI" Watch "Help on CMP for J2EE-RI" New topic
Author

Help on CMP for J2EE-RI

HanMing Low
Ranch Hand

Joined: Oct 18, 2001
Posts: 196
Hi,
I'm having a problem running an example in "EJB" by Richard Monson-Haefel.
I've created a CMP Entity Bean and successfully deployed to the J2EE-RI Server.
However, when I ran the client I experience a RollbackException during create
I've tested my findByPrimaryKey and is working fine, so I guess the ejbLoad and ejbStore is ok too.
Thus, I check my SQL statement for create row
INSERT INTO CUSTOMER (FIRST_NAME, ID, LASTNAME) VALUES (?, ?, ?)
The problem is that my primary key is ID - Integer which is the first column in my table.
FIRST_NAME and LAST_NAME are char that sllow null.
Will the server be smart enough to know where to map the value for which column.
I've tried to switch the position of the column in the SQL statement but does not help.
Any advice is greatly appreciated.
Thanks.

Han Ming

##################################################
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.RemoteException: Transaction aborted (possibly due to transaction time out).; nested exception is: javax.transaction.RollbackException; nested exception is: javax.transaction.RollbackExceptionjava.rmi.RemoteException: Transaction aborted (possibly due to transaction time out).; nested exception is: javax.transaction.RollbackException; nested exception is: javax.transaction.RollbackExceptionjavax.transaction.RollbackException <<no stack trace available>>
Lakshmi Anantharaman
Ranch Hand

Joined: Aug 01, 2001
Posts: 58
You could change the query to reflect the columns in your table /
In the real work the best way to create Entity beans would be leave the container manage Persistence. In this case you may not need to write any query at all.
Lakshmi
HanMing Low
Ranch Hand

Joined: Oct 18, 2001
Posts: 196
Hi,
I've managed to figure out the problem.
There are 2 problems when trying to deployed the CustomerBean example of "EJB" chapter 6 on a J2EE-RI.
So I guess it might be a good idea to write my experience down so that others can avoid it.
1) in your Remote interfaces (Home and Object), if you throws other than RemoteException, all the other exceptions
e.g. CreateException, FinderException
must be thrown in the corresponding methods in the Bean class.
2) for CMP Entity Bean, the ejbCreate show in the example only has a
setId(id);
you actually need to add
setFirstName("");
setLastName("");
adding
setFirstName(null);
setLastName(null);
does not work.
3) the SQL statement generated by the deployment setting is slightly incorrect. Obviously, you need to change the table name to your actual table. In addition, you need to change the field name e.g from firstName to FIRST_NAME and, importantly, removed the " from all the statement.
4) But, do not rearrange any order of field generated.
I guess this is much I have to correct to get the bean running correctly.
Hope it helps.
Cheers.

Han Ming
 
Don't get me started about those stupid light bulbs.
 
subject: Help on CMP for J2EE-RI