2 Replies Latest reply on Nov 29, 2005 1:35 PM by Frank Stolle

    Problem with Session.get

    Frank Stolle Newbie

      Hi,

      I've got a really strange problem.

      I've defined the following EntityBean:

      package de.hotware.dataobjects.entities;
      
      import java.io.Serializable;
      import java.util.Collection;
      
      import javax.persistence.Basic;
      import javax.persistence.CascadeType;
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.FetchType;
      import javax.persistence.GeneratorType;
      import javax.persistence.Id;
      import javax.persistence.JoinColumn;
      import javax.persistence.OneToMany;
      import javax.persistence.OneToOne;
      import javax.persistence.Table;
      import javax.persistence.AccessType;
      
      @Entity(access = AccessType.FIELD)
      @Table(name = "categories")
      public class Category implements Serializable {
       @Id(generate = GeneratorType.IDENTITY)
       @Column(name = "id")
       private int id;
      
       @Basic(optional = false)
       @Column(name = "foreignid", length = 10)
       private String networkId;
      
       @OneToOne(optional = false, fetch = FetchType.LAZY)
       @JoinColumn(name = "foreigner", nullable = false)
       private AffiliateNetwork network;
      
       @Basic(optional = false)
       @Column(name = "name", nullable = false)
       private String name;
      
       @OneToOne(fetch = FetchType.LAZY)
       @JoinColumn(name = "parent")
       private Category parent;
      
       @OneToMany(mappedBy = "parent")
       private Collection<Category> subcategories;
      
       @Override
       public boolean equals(Object obj) {
       if (!(obj instanceof Category))
       return false;
       Category o = (Category) obj;
       return o.id == id;
       }
      
       public int getId() {
       return id;
       }
      
       public void setId(int id) {
       this.id = id;
       }
      
       public String getName() {
       return name;
       }
      
       public void setName(String name) {
       this.name = name;
       }
      
       public AffiliateNetwork getNetwork() {
       return network;
       }
      
       public void setNetwork(AffiliateNetwork network) {
       this.network = network;
       }
      
       public String getNetworkId() {
       return networkId;
       }
      
       public void setNetworkId(String networkId) {
       this.networkId = networkId;
       }
      
       public Category getParent() {
       return parent;
       }
      
       public void setParent(Category parent) {
       this.parent = parent;
       }
      
       public Collection<Category> getSubcategories() {
       return subcategories;
       }
      
       public void setSubcategories(Collection<Category> subcategories) {
       this.subcategories = subcategories;
       }
      
      }
      


      And in the Sessionbean I want to search for an entity:

      @Stateless
      @Remote( { TestBean.class })
      public class TestBeanBean implements TestBean {
       @PersistenceContext(unitName = "hotwaredb")
       private Session em;
      
       public Category test() {
       return (Category) em.get(Category.class, 1);
       }
      }
      


      The remote-client calls the test-method and the result is null. But the entity with id 1 exists in the database.

      This is the Output of JBOSS:
      22:28:48,307 DEBUG [DefaultLoadEventListener -- org.hibernate.event.def.DefaultLoadEventListener] loading entity: [dataobjects.entities.Category#1]
      22:28:48,307 DEBUG [DefaultLoadEventListener -- org.hibernate.event.def.DefaultLoadEventListener] attempting to resolve: [dataobjects.entities.Category#1]
      22:28:48,308 DEBUG [DefaultLoadEventListener -- org.hibernate.event.def.DefaultLoadEventListener] object not resolved in any cache: [dataobjects.entities.Category#1]
      22:28:48,308 DEBUG [AbstractEntityPersister -- org.hibernate.persister.entity.AbstractEntityPersister] Fetching entity: [dataobjects.entities.Category#1]
      22:28:48,309 DEBUG [Loader -- org.hibernate.loader.Loader] loading entity: [dataobjects.entities.Category#1]
      22:28:48,309 DEBUG [AbstractBatcher -- org.hibernate.jdbc.AbstractBatcher] about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
      22:28:48,311 DEBUG [ConnectionManager -- org.hibernate.jdbc.ConnectionManager] opening JDBC connection
      22:28:48,312 DEBUG [SQL -- org.hibernate.jdbc.AbstractBatcher] select category0_.id as id74_0_, category0_.foreignid as foreignid74_0_, category0_.foreigner as foreigner74_0_, category0_.name as name74_0_, category0_.parent as parent74_0_ from categories category0_ where category0_.id=?
      22:28:48,313 INFO [STDOUT -- org.jboss.logging.util.LoggerStream] Hibernate: select category0_.id as id74_0_, category0_.foreignid as foreignid74_0_, category0_.foreigner as foreigner74_0_, category0_.name as name74_0_, category0_.parent as parent74_0_ from categories category0_ where category0_.id=?
      22:28:48,313 DEBUG [AbstractBatcher -- org.hibernate.jdbc.AbstractBatcher] preparing statement
      22:28:48,315 DEBUG [IntegerType -- org.hibernate.type.NullableType] binding '1' to parameter: 1
      22:28:48,317 DEBUG [AbstractBatcher -- org.hibernate.jdbc.AbstractBatcher] about to open ResultSet (open ResultSets: 0, globally: 0)
      22:28:48,318 DEBUG [Loader -- org.hibernate.loader.Loader] processing result set
      22:28:48,319 DEBUG [Loader -- org.hibernate.loader.Loader] done processing result set (0 rows)
      22:28:48,319 DEBUG [AbstractBatcher -- org.hibernate.jdbc.AbstractBatcher] about to close ResultSet (open ResultSets: 1, globally: 1)
      22:28:48,320 DEBUG [AbstractBatcher -- org.hibernate.jdbc.AbstractBatcher] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
      22:28:48,321 DEBUG [AbstractBatcher -- org.hibernate.jdbc.AbstractBatcher] closing statement
      22:28:48,322 DEBUG [ConnectionManager -- org.hibernate.jdbc.ConnectionManager] aggressively releasing JDBC connection
      22:28:48,323 DEBUG [ConnectionManager -- org.hibernate.jdbc.ConnectionManager] closing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
      22:28:48,323 DEBUG [Loader -- org.hibernate.loader.Loader] total objects hydrated: 0
      22:28:48,324 DEBUG [StatefulPersistenceContext -- org.hibernate.engine.StatefulPersistenceContext] initializing non-lazy collections
      22:28:48,324 DEBUG [Loader -- org.hibernate.loader.Loader] done entity load
      22:28:48,325 DEBUG [CacheSynchronization -- org.hibernate.transaction.CacheSynchronization] transaction before completion callback
      22:28:48,326 DEBUG [JDBCContext -- org.hibernate.jdbc.JDBCContext] before transaction completion
      22:28:48,327 DEBUG [SessionImpl -- org.hibernate.impl.SessionImpl] before transaction completion
      22:28:48,328 DEBUG [SessionImpl -- org.hibernate.impl.SessionImpl] closing session
      22:28:48,332 DEBUG [ConnectionManager -- org.hibernate.jdbc.ConnectionManager] connection already null in cleanup : no action
      22:28:48,333 DEBUG [CacheSynchronization -- org.hibernate.transaction.CacheSynchronization] transaction after completion callback, status: 3
      22:28:48,333 DEBUG [JDBCContext -- org.hibernate.jdbc.JDBCContext] after transaction completion
      22:28:48,334 DEBUG [SessionImpl -- org.hibernate.impl.SessionImpl] after transaction completion
      


      But the following sql-statement running directly on the server returns exactly one row:

      select category0_.id as id74_0_, category0_.foreignid as foreignid74_0_, category0_.foreigner as foreigner74_0_, category0_.name as name74_0_, category0_.parent as parent74_0_ from categories category0_ where category0_.id=1
      


      Any ideas?

      Thank you for your help!

      Bye Frank