3 Replies Latest reply on Jun 22, 2006 2:03 PM by Achim Hilwers

    Loosing PK on query

    Achim Hilwers Newbie

      Hello!

      I'm having a strange problem with my EJBs. I have created a base-class for my entity-ejbs that contains the primary-key-field and some other fields:

      ...
      @MappedSuperclass
      public class JbsObject {
      
       private long id;
      
       @Id
       public long getId() {
       return id;
       }
      
       public void setId(long id) {
       this.id = id;
       }
      
      ...
      }
      


      Now I have an entity-ejb named "Address" that defines some more fields like "name", ...

      @Entity
      public class Address extends JbsObject implements Serializable {
      ...
      }
      


      The tables are created correctly and I can add new entities without any problems.

      Now I want to fetch a list of addresses with a simple query in my stateless session-bean "AddressesBean":

      @Stateless
      public class AddressesBean implements Addresses {
      
       @PersistenceContext(unitName="testapp")
       private EntityManager manager;
      
       public List getAllAddresses() {
       Query q = manager.createQuery("from Address");
       return q.getResultList();
       }
      ...
      }
      


      When I invoke this method from my client-application I can retrieve all addresses with their data except their id. The id of every instance is 0. I have printed out the ids within the getAllAddresses-function - all is ok there. Only on the client I have no ids.

      What am I doing wrong?

      I'm using JBoss 4.04GA with Linux.

      Achim