• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Help on CMP for J2EE-RI

 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>>
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic