[jboss-user] [EJB/JBoss] - CMP Persistance 2.1 with HSQLDB on JBoss 4.0.5GA Failing?

karianna do-not-reply at jboss.com
Tue Mar 20 14:52:22 EDT 2007


Hi all,

I'm following through the OReilly's Enterprise JavaBeans 4th Edition using Jboss 4.0.5 GA (configured for J2EE1.4), with JDK 1.4.2_13 andusing the default inbuilt HSQLDB.  I have come across a strange error when trying to find the entity bean I have created:

---------------------------------

18:37:15,046 ERROR [CabinEJB#findByPrimaryKey] Find failed
java.sql.SQLException: Unexpected token: FROM in statement [SELECT  FROM CABINEJB t0_CabinEJB WHERE ]

---------------------------------

I'm guessing the CMP code should have produced SQL which reads something like this:

SELECT * FROM CABINEJB t0_CabinEJB WHERE id = ?

---------------------------------
My ejb-jar.xml looks like this:
---------------------------------

  | <enterprise-beans>
  | 	<entity>
  | 		<ejb-name>CabinEJB</ejb-name>
  | 		<home>org.martijnverburg.ejb.CabinHomeRemote</home>
  | 		<remote>org.martijnverburg.ejb.CabinRemote</remote>
  | 		<ejb-class>org.martijnverburg.ejb.CabinBean</ejb-class>
  | 		<persistence-type>Container</persistence-type>
  | 		<prim-key-class>java.lang.Integer</prim-key-class>
  | 		<reentrant>False</reentrant>
  | 		<abstract-schema-name>Cabin</abstract-schema-name>
  | 		<cmp-field>
  | 			<field-name>id</field-name>
  | 		</cmp-field>
  | 		<cmp-field>
  | 			<field-name>name</field-name>
  | 		</cmp-field>
  | 		<prim-key-field>id</prim-key-field>
  | 		<security-identity>
  | 			<use-caller-identity />
  | 		</security-identity>
  | 	</entity>
  | </enterprise-beans>
  | 

---------------------------------
My CabinHomeRemote looks like this:
---------------------------------

  | package org.martijnverburg.ejb;
  | 
  | <snip imports>
  | 
  | public interface CabinHomeRemote extends EJBHome {
  |     
  |     public CabinRemote create(Integer id) throws CreateException, RemoteException;
  |     
  |     public CabinRemote findByPrimaryKey(Integer pk) throws FinderException, RemoteException;
  | 
  | }
  | 
---------------------------------
My CabinRemote looks like this:
---------------------------------

  | package org.martijnverburg.ejb;
  | 
  | <snip imports>
  | 
  | public interface CabinRemote extends EJBObject {
  | 
  |     public String getName() throws RemoteException;
  |     
  |     public void setName(String name) throws RemoteException;
  | }
  | 
---------------------------------
My CabinBean looks like this:
---------------------------------

  | package org.martijnverburg.ejb;
  | 
  | <snip imports>
  | 
  | public abstract class CabinBean implements EntityBean {
  |     
  |     public Integer ejbCreate(Integer id) throws CreateException {
  |         this.setId(id);
  |         return null;
  |     }
  | 
  |     public abstract void setId(Integer id);
  |     
  |     public abstract Integer getId();
  |     
  |     public abstract void setName(String name);
  |     
  |     public abstract String getName();
  | 
  |     <snip mandatory ejbX() methods>
  | }
  | 
---------------------------------
The calling client looks like this:
---------------------------------

  | package org.martijnverburg.ejb.client;
  | 
  | <snip imports>
  | 
  | public class CabinBeanClient {
  |     
  |     public static void createCabin(Integer id, String name) {
  |         try {
  | 
  |             Context jndiContext = getInitialContext();
  |             Object ref = jndiContext.lookup("CabinHomeRemote"); 
  |             CabinHomeRemote home = (CabinHomeRemote)PortableRemoteObject.narrow(ref, CabinHomeRemote.class);
  |             
  |             CabinRemote cabin1 = home.create(id);
  | 
  |             cabin1.setName(name);
  |             
  |         } catch <snip catch blocks>
  |     }
  | 
  |     public static String findCabinName(Integer id) {
  |         
  |         String name = null;
  |         
  |         try {
  |             Context jndiContext = getInitialContext();
  |             Object ref = jndiContext.lookup("CabinHomeRemote");
  |             CabinHomeRemote home = (CabinHomeRemote)PortableRemoteObject.narrow(ref, CabinHomeRemote.class);
  |             
  |             // Find the bean
  |             CabinRemote cabin1 = home.findByPrimaryKey(id);
  | 
  |             // Get the attribute on that bean
  |             name = cabin1.getName();
  |         } catch <snip catch blocks>
  |         
  |         return name;
  |     }
  |     
  |     /**
  |      * Get the initial jndi context for this app server, so we can look 
  |      * up entity beans etc.
  |      * 
  |      * @return The context
  |      * @throws NamingException 
  |      */
  |     private static Context getInitialContext() throws NamingException {
  |         // Calling this default constructor means that the jndi.properties gets
  |         // searched for and used on the classpath
  |         return new InitialContext();
  |     }
  | }
  | 

Any ideas? :)

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4029954#4029954

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4029954



More information about the jboss-user mailing list