日期:2014-05-19  浏览次数:20747 次

EJB 3.0 no session or session was closed,急啊!
小弟最近参与了一个邮件系统的开发,在MyEclipse 6.6 Jboss 4.2.2环境下,在后台用的是EJB3.0,有三个实体bean:Admin,Group,Linkman.admin和group是一对多,admin和linkman是一对多,group和linkman也是一对多,现在我根据admin加载group可以,但admin加载linkman不行,就会报以下错误:failed to lazily initialize a collection of role: com.spg.bean.Admin.cat, no session or session was closed!还望各位多多帮忙。
下面是admin的代码:
package com.spg.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;

import org.hibernate.annotations.IndexColumn;

@Entity
public class Admin implements Serializable {

private static final long serialVersionUID = 7226663383506361021L;
private String name;/**系统用户姓名*/
private String password;/**系统用户密码*/
private Integer admin_id;/**系统用户ID*/
private String qq;/**系统用户QQ*/
private String address;/**系统用户详细地址*/

private String city;/**系统用户所在城市*/
private String country;/**系统用户所在国家*/
private String nickName;/**系统用户所在国家*/

private List<Group> groups = new ArrayList<Group>();
private List<Contactname> cat = new ArrayList<Contactname>();

@Column(nullable = false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(nullable = false)
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}

public String getQq() {
return qq;
}

public void setQq(String qq) {
this.qq = qq;
}
@Column(nullable = false)
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Id
@GeneratedValue
public Integer getAdmin_id() {
return admin_id;
}

public void setAdmin_id(Integer admin_id) {
this.admin_id = admin_id;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getNickName() {
return nickName;
}
public void setNickName(String nickName) {
this.nickName = nickName;
}
@OneToMany(mappedBy = "admin", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@OrderBy(value = "group_id asc")
public List<Group> getGroups() {
return groups;
}

public void setGroups(List<Group> groups) {
this.groups = groups;
}
@Override
public int hashCode() {
int hash = 0;
hash += (this.admin_id != null ? this.admin_id.hashCode() : 0);
return hash;
}

/**
* 确定其他对象是否等于此 Admin ,当且仅当 参数不为 null 且该参数是具有与此对象相同 id 字段值的 Admin 对象时, 结果才为
* <code>true</code>。

* @param 对象,要比较的引用对象
* 如果此对象与参数相同,则
* @return <code>true</code>; 否则为 <code>false</code>。
*/
@Override
public boolean equals(Object object) {
if (!(object instanceof Admin)) {
return false;
}
Admin other = (Admin) object;
if (this.admin_id != other.admin_id
&& (this.admin_id == null || !this.admin_id
.equals(other.admin_id)))
return false;
else if (this.name != n