-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How do I know which relationship shall be eager fetched?
PostPosted: Tue Jul 07, 2009 3:22 pm 
Regular
Regular

Joined: Tue Feb 17, 2009 3:36 pm
Posts: 78
I get an exception as the following:
Quote:
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:86)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:140)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
at com.xyz.smyapp.domain.group.GroupCategory_$$_javassist_14.equals(GroupCategory_$$_javassist_14.java)

And the GroupCategory class is defined as the following:
Code:
@Entity
@Table(name = "category")
public class GroupCategory implements Serializable {

   /**
    *
    */
   private static final long serialVersionUID = 7217161816809035673L;

   private Integer id;

   private String name;

   private List<GroupCategory> childCategories = new ArrayList<GroupCategory>();

   private GroupCategory parentCategory;

   /**
    * @return the id
    */
   @Id
   @Column(name = "id")
   public Integer getId() {
      return id;
   }

   /**
    * @param id
    *            the id to set
    */
   public void setId(Integer id) {
      this.id = id;
   }

   /**
    * @return the name
    */
   @Column(name = "name", nullable = false, length = 80)
   public String getName() {
      return name;
   }

   /**
    * @param name
    *            the name to set
    */
   public void setName(String name) {
      this.name = name;
   }

   /**
    * @return the childCategories
    */
   @OneToMany
   public List<GroupCategory> getChildCategories() {
      return childCategories;
   }

   /**
    * @param childCategories
    *            the childCategories to set
    */
   public void setChildCategories(List<GroupCategory> childCategories) {
      this.childCategories = childCategories;
   }

   /**
    * @return the parentCategory
    */
   @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
   @JoinColumn(name = "PARENT_ID")
   public GroupCategory getParentCategory() {
      return parentCategory;
   }

   /**
    * @param parentCategory
    *            the parentCategory to set
    */
   public void setParentCategory(GroupCategory parentCategory) {
      this.parentCategory = parentCategory;
   }

   /*
    * (non-Javadoc)
    *
    * @see java.lang.Object#hashCode()
    */
   @Override
   public int hashCode() {
      final int prime = 31;
      int result = 1;
      result = prime * result
            + ((childCategories == null) ? 0 : childCategories.hashCode());
      result = prime * result + ((id == null) ? 0 : id.hashCode());
      result = prime * result + ((name == null) ? 0 : name.hashCode());
      result = prime * result
            + ((parentCategory == null) ? 0 : parentCategory.hashCode());
      return result;
   }

   /*
    * (non-Javadoc)
    *
    * @see java.lang.Object#equals(java.lang.Object)
    */
   @Override
   public boolean equals(Object obj) {
      if (this == obj)
         return true;
      if (obj == null)
         return false;
      if (getClass() != obj.getClass())
         return false;
      GroupCategory other = (GroupCategory) obj;
      if (childCategories == null) {
         if (other.childCategories != null)
            return false;
      } else if (!childCategories.equals(other.childCategories))
         return false;
      if (id == null) {
         if (other.id != null)
            return false;
      } else if (!id.equals(other.id))
         return false;
      if (name == null) {
         if (other.name != null)
            return false;
      } else if (!name.equals(other.name))
         return false;
      if (parentCategory == null) {
         if (other.parentCategory != null)
            return false;
      } else if (!parentCategory.equals(other.parentCategory))
         return false;
      return true;
   }

}

How do I find out which relationship shall not be lazy fetched?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.