4 Replies Latest reply on Aug 16, 2005 7:01 PM by Jeremy Cowgar

    EntityManager.persist saving to database but not updating ob

    Jeremy Cowgar Newbie

      I am using 4.0.3RC2 and have an Entity bean from the EJB3 example (Fund, Investor, etc...). I created a simple app that creates a new Fund and then calls EntityManager.persist(). The data is written to the database but my POJO is not updated with the ID value created.

      OK, further testing. It seems that in the Session bean, the getId() is there and valid but my remote application is not getting it... Here's a few code snipplets:

      Fund.java:

      ...
      
      @Entity
      @Table (name="fund")
      public class Fund implements Serializable {
      
      ...
      
       @Id (generate = GeneratorType.AUTO)
       public int getId() {
       return id;
       }
      
       ...
      


      BankBean.java:
      ...
      
      @Stateless
      public class BankBean implements BankLocal, BankRemote {
       @PersistenceContext (unitName="task")
       EntityManager em;
      
       public void addFund(Fund fund) {
       em.persist(fund);
       System.out.println(fund.getId()); // Correct Output
       }
      
      ...
      


      MyRemoteClient.java:
      ...
      
      public class MyRemoteClient {
       public static void main(String[] args) throws Exception {
       InitialContext ctx = new InitialContext();
       Bank bank = (Bank) ctx.lookup(BankRemote.class.getName());
      
       Fund fund = new Fund();
       fund.setName("Jeremy");
       fund.setGrowthrate(10);
       bank.addFund(fund);
      
       System.out.println(fund.getId()); // 0 (Zero) all the time.
      
      ...
      


      Any ideas?

      Jeremy