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.
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
Joined: Oct 18, 2001
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.