0 Replies Latest reply on Jan 12, 2008 8:43 AM by galrub

    Id var not updated after persist

    galrub

      hello all, using jboss 4.2.2 (red-hat developer studio) and mysql 5;

      after doing persist the Id retrun null... here is the code:

      1st, the table in DB:

      create table test (
       ID int(10) NOT NULL auto_increment,
       NAME VARCHAR(15),
       PRIMARY KEY (ID)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
      


      the -ds.xml
      <datasources>
       <local-tx-datasource>
       <jndi-name>work.datasource</jndi-name>
       <connection-url>jdbc:mysql://localhost:3306/work</connection-url>
       <driver-class>com.mysql.jdbc.Driver</driver-class>
       <user-name>un</user-name>
       <password>pw</password>
       <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
       <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
       <metadata>
       <type-mapping>mySQL</type-mapping>
       </metadata>
       </local-tx-datasource>
      </datasources>
      


      the persistence.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" ...............
      <persistence-unit name="tester" transaction-type="JTA">
       <jta-data-source>java:/work.datasource</jta-data-source>
       <properties>
       <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
       <property name="hibernate.show_sql" value="true"/>
       </properties>
       </persistence-unit>
      </persistence>
      

      the entity, manager, end tester EJB's:
      @Entity
      @Table(name = "test")
      public class TestEntity implements Serializable
      {
       @Id
       @Column(name = "id")
       @GeneratedValue
       private Integer someId;
      
       @Column(name = "name")
       private String someName;
      
       getters/Setters.......
      
       public String toString()
       {
       return "id = " + someId + ", Name = " + someName;
       }
      }
      
      public @Stateless class TestManagerBean implements TestManager
      {
       private String GET_BY_ID_EJBQL = "SELECT x FROM TestEntity x WHERE x.id = ?";
      
       @PersistenceContext(unitName="tester")
       private EntityManager manager;
      
       public void create(TestEntity test)
       {
       manager.persist(test);
       }
      
       public TestEntity getById(Integer id)
       {
       return (TestEntity) manager.createQuery(
       GET_BY_ID_EJBQL).setParameter(1, id).getSingleResult();
       }
      
      }
      
      public @Stateless class RunTestBean implements RunTest
      {
      
       @EJB private TestManager manager;
      
       public void test()
       {
       TestEntity testEntity = new TestEntity();
       testEntity.setSomeName("abcd");
       manager.create(testEntity);
       System.out.println("return = " + testEntity);
       }
      
      }
      
      


      there is also a standalone the looks up "RunTestBean/remote"
      and execute test().

      the output print out is:
      15:12:00,852 INFO [STDOUT] return = id = null, Name = abcd

      can anyone tell me how to "persuade" the container to kindly update the id
      from the table (the persist works, got a new line in table!).

      Thanks in advance