2 Replies Latest reply on Oct 18, 2006 4:12 PM by John Gilbert

    Problem with EmbeddedId

    J-C jc Apprentice

      I use JBoss Embeddable EJB3 alpha7 with hsql.

      I try to use an embeddedId. I get the composite project from JBoss EJB3 RC7 tutorial. When I persist the Customer object I have an exception

      could not insert: [persistence.ejb3.entity.Customer]


      I have 2 classes:
      package persistence.ejb3.entity;
      import javax.persistence.Embeddable;
      @Embeddable
      public class CustomerPK implements java.io.Serializable
      {
       private long id;
       private String name;
      
      
       public CustomerPK(){}
      
       public CustomerPK(long id, String name) {
       this.id = id;
       this.name = name;
       }
      
       public long getId(){return id;}
      
       public void setId(long id) { this.id = id; }
      
       public String getName() { return name; }
      
       public void setName(String name) { this.name = name; }
      
       public int hashCode() {
       return (int) id + name.hashCode();
       }
      
       public boolean equals(Object obj)
       {
       if (obj == this) return true;
       if (!(obj instanceof CustomerPK)) return false;
       if (obj == null) return false;
       CustomerPK pk = (CustomerPK) obj;
       return pk.id == id && pk.name.equals(name);
       }
      }
      

      package persistence.ejb3.entity;
      
      import javax.persistence.EmbeddedId;
      import javax.persistence.Entity;
      import javax.persistence.Transient;
      
      @Entity
      public class Customer implements java.io.Serializable
      {
       CustomerPK pk;
      
       public Customer()
       {
       }
      
       @EmbeddedId
       public CustomerPK getPk()
       {
       return pk;
       }
      
       public void setPk(CustomerPK pk)
       {
       this.pk = pk;
       }
      
       @Transient
       public String getName()
       {
       return pk.getName();
       }
      }
      


      And the exception:
      java.sql.SQLException: Table not found in statement [insert into Customer (name, id) values (?, ?)]
       at org.hsqldb.jdbc.Util.throwError(Unknown Source)
       at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
       at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
       at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.doPrepareStatement(BaseWrapperManagedConnection.java:349)
       at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.prepareStatement(BaseWrapperManagedConnection.java:344)
       at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:187)
       at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:497)
       at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:94)
       at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
       at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:218)
       at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2106)
       at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2503)
       at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
       at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
       at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
       at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
       at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
       at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
       at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:993)
       at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:340)
       at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:475)
       at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:3074)
       at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:2632)
       at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:1194)
       at org.jboss.tm.TxManager.commit(TxManager.java:588)
       at persistence.ejb3.tests.PeristenceTestCase.testID(PeristenceTestCase.java:33)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at junit.framework.TestCase.runTest(TestCase.java:154)
       at junit.framework.TestCase.runBare(TestCase.java:127)
       at junit.framework.TestResult$1.protect(TestResult.java:106)
       at junit.framework.TestResult.runProtected(TestResult.java:124)
       at junit.framework.TestResult.run(TestResult.java:109)
       at junit.framework.TestCase.run(TestCase.java:118)
       at junit.framework.TestSuite.runTest(TestSuite.java:208)
       at junit.framework.TestSuite.run(TestSuite.java:203)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
      WARN 07-06 10:07:33,266 (Log4JLogger.java:warn:104) -SQL Error: -22, SQLState: S0002
      ERROR 07-06 10:07:33,266 (Log4JLogger.java:error:114) -Table not found in statement [insert into Customer (name, id) values (?, ?)]
      ERROR 07-06 10:07:33,266 (Log4JLogger.java:error:119) -Could not synchronize database state with session
      org.hibernate.exception.SQLGrammarException: could not insert: [persistence.ejb3.entity.Customer]
       at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
       at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
       at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2140)
       at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2503)
       at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
       at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
       at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
       at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
       at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
       at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
       at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:993)
       at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:340)
       at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:475)
       at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:3074)
       at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:2632)
       at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:1194)
       at org.jboss.tm.TxManager.commit(TxManager.java:588)
       at persistence.ejb3.tests.PeristenceTestCase.testID(PeristenceTestCase.java:33)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at junit.framework.TestCase.runTest(TestCase.java:154)
       at junit.framework.TestCase.runBare(TestCase.java:127)
       at junit.framework.TestResult$1.protect(TestResult.java:106)
       at junit.framework.TestResult.runProtected(TestResult.java:124)
       at junit.framework.TestResult.run(TestResult.java:109)
       at junit.framework.TestCase.run(TestCase.java:118)
       at junit.framework.TestSuite.runTest(TestSuite.java:208)
       at junit.framework.TestSuite.run(TestSuite.java:203)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
      Caused by: java.sql.SQLException: Table not found in statement [insert into Customer (name, id) values (?, ?)]
       at org.hsqldb.jdbc.Util.throwError(Unknown Source)
       at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
       at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
       at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.doPrepareStatement(BaseWrapperManagedConnection.java:349)
       at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.prepareStatement(BaseWrapperManagedConnection.java:344)
       at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:187)
       at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:497)
       at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:94)
       at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
       at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:218)
       at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2106)
       ... 30 more


      Is EmbeddedId supported by JBoss embeddable EJB3 ?

      Any help is welcome !