2 Replies Latest reply on Jun 1, 2009 3:47 AM by achalov

    Remote EJB call problem

    achalov

      I have a problem accessing generated primary key for entity when call create method through remote ejb3 interface. The piece of SLSB code is

       public T persist(T entity) {
       getEntityManager().persist(entity);
       return entity;
       }
      
       public void flush() {
       getEntityManager().flush();
       }
      

      , entity
       @Id
       @Column(nullable = false, name = "id")
       @SequenceGenerator(name = "CountrySequenceGenerator", sequenceName = "country_id_seq")
       @GeneratedValue(strategy = GenerationType.AUTO, generator = "CountrySequenceGenerator")
       private Long id;
      

      and client call
       CountryRemote countryRemote = JBossEjbLocator.getLocator().getReference(CountryRemote.class);
       CountryLocal countryLocal = JBossEjbLocator.getLocator().getReference(CountryLocal.class);
      
       public Long createCountryLocal() {
       Country country = new Country();
       country.setName("Test Country");
       countryLocal.persist(country);
       countryLocal.flush();
       return country.getId();
       }
      
       public Long createCountryRemote() {
       Country country = new Country();
       country.setName("Test Country");
       countryRemote.persist(country);
       countryRemote.flush();
       return country.getId();
       }
      

      Actually local call works fine. Generated id for country object are set when flush() called, but calls through remote interface always return null.
      When I look through database records I see that records successfully added in both cases. Calling refresh() on entity gives no result.
      JBoss AS version jboss5.0.1.GA, database PostgreSQL 8.3. JDBC3 driver used.
      Client code is called from JSF managed bean.
      What I am douing wrong? Actually, I think that there should be no difference in the way I call ejb3.
      Thanks for your answers in advance.

        • 1. Re: Remote EJB call problem
          jaikiran

          When you use remote calls, the parameters and return types are serialized/deserialized. So your call to the persist method on the bean from the client cannot expect the "country" parameter to be passed by reference.

          Change this in client:

          countryRemote.persist(country);
          countryRemote.flush();
          return country.getId();


          to

          Country persistedCountry = countryRemote.persist(country);
          countryRemote.flush();
          return persistedCountry.getId();


          i.e. work on the returned object.


          • 2. Re: Remote EJB call problem
            achalov

            Thanx. I surprized that I didn't get it myself. :(