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?