67,512
社区成员
发帖
与我相关
我的任务
分享
那个注解我没有!怎么弄啊!好久没有写java了!(*^__^*) 嘻嘻
本人使用Hibernate查询数据库得到一个集合然后想使用json lib将集合转换为json对象,来实现前台的ajax翻页 现在遇到的问题是 不使用属性过滤陷入属性级联的死循环 jsonArray = JSONArray.fromObject(usersList); net.sf.json.JSONException: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.jzbr.entity.Groups.bbsusersList, no session or session was closed 使用属性过滤 JsonConfig config = new JsonConfig(); config.setExcludes(new String[]{"bbsusersList"}); jsonArray = JSONArray.fromObject(usersList); net.sf.json.JSONException: There is a cycle in the hierarchy!
那个注解我没有!怎么弄啊!好久没有写java了!(*^__^*) 嘻嘻
额 我使用的是 Hibernate 注解方式查询的数据可以属性能直接设置延迟加载?@Entity @Component("users") public class Users implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue @Column(name = "id") private Integer id; @Column(name = "username", length = 16, nullable = false, unique = true) private String username; @Column(name = "password") private String password; @Column(name = "rDate") private Date rDate; @Column(name = "state") private byte state; @ManyToOne @JoinColumn(name = "roles_id") private Roles roles; @OneToOne(mappedBy = "users",cascade=CascadeType.ALL) private BBSUsers bbsUsers;
@Entity
@Component("users")
public class Users implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
@Column(name = "id")
private Integer id;
@Column(name = "username", length = 16, nullable = false, unique = true)
private String username;
@Column(name = "password")
private String password;
@Column(name = "rDate")
private Date rDate;
@Column(name = "state")
private byte state;
@ManyToOne
@JoinColumn(name = "roles_id")
private Roles roles;
@OneToOne(mappedBy = "users",cascade=CascadeType.ALL)
private BBSUsers bbsUsers;