本人使用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!
HibernateJSON
现在遇到的问题是
不使用属性过滤陷入属性级联的死循环 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!
HibernateJSON
解决方案 »
- 用java可以实现将vox格式音频文件转换成wav格式音频文件,请求指导
- 获取页面数据存放到本地数据库
- 求助 关于JPQL 传IN参数问题
- 关于存储过程的问题
- C:\WINDOWS\system32\drivers\etc\host如何配置域名映射,tomcat
- 如何在WEB页面实现订单自动提醒功能
- ant 的builder.xml问题
- 实现hibernate的一对多时,List中出现很多null,怎么回事?
- jsp+servlet+bean做的一个非常具体处理一件事情的东西,但是要求这个过程中遇到的问题,比如文件找不到。。最后都通过一个页面报告给客户
- 在JB5中为什么找不到javax.ejb 包
- javax.servlet.jar和serlvet-api.jar是什么关系
- java两个虚拟机之间可以直接管道通讯吗
<!-- 延迟加载 -->
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping> <filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>配置了延迟加载貌似就不会出现这样的问题,大概异常的思路是这些地方,楼主!自己在具体的看看!
@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;
第二个请注意config对象未作为参数使用进去
话说燕子还会JAVA?给我加个关注啊 ,然后才能给你发私信的。