In my project, I use PostgreSQL and Hibernate to connect to my ZUL and all that noise. The connection I am trying to do is, in a Facebook manner, an user entry whose ID appears in several Posts and Comments. This calls for a OneToMany and a ManyToOne kind of deal. This is my first time doing these kind of connections in ZK and Hibernate, and I would appreciate it if I were pointed out where I"m wrong.

Here are the errors that pop out several times:

Caused by: org.hyakkendana-hashigozake.com.zel.ELException: org.hibernate.LazyInitializationException: could not initialize proxy - no SessionCaused by: org.hibernate.LazyInitializationException: could not initialize proxy - no SessionGrave: org.hyakkendana-hashigozake.com.zk.ui.UiException: org.hibernate.LazyInitializationException: could not initialize proxy - no Session at Grave: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: pojos.Post.comments, could not initialize proxy - no Session And here are the Post, Comment and FBUser java files:




You are watching: Failed to lazily initialize a collection of role

org.hibernate.annotations.Entity(dynamicUpdate = true)public class Post implements java.io.Serializable {
OneToMany(fetch = FetchType.EAGER, mappedBy = "post", cascade = CascadeType.ALL)private Collection comments = new LinkedHashSet();//getters, setters and other devices
org.hibernate.annotations.Entity(dynamicUpdate = true)public class Comment implements java.io.Serializable {
org.hibernate.annotations.Entity(dynamicUpdate = true)public class Fbuser implements java.io.Serializable {
OneToMany(fetch = FetchType.EAGER, mappedBy = "fbuser", cascade = CascadeType.ALL)private Set comments = new HashSet(0);
OneToMany(fetch = FetchType.EAGER, mappedBy = "fbuser", cascade = CascadeType.ALL)private Collection posts = new LinkedHashSet();//getters, setters and other tools And my connector with Hibernate is basically this code several times with different table names and ID"s:

public List getPosts() throws Exception session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); String toDo = "FROM Post ORDER BY postid DESC"; List posts = session.createQuery(toDo).list(); session.getTransaction().commit(); session.close(); return posts; Any help is appreciated!


You are accesing the roles when your hibernate session is already closed. Downpart of hibernate lazy collections

Eager fetch will avoid this problem or set up mechanisme that will use a new hibernate session to fetch the roles

1 Answer


Sort by » oldest newest most voted
0
*
hawk 2939 ● 1 ● 5 http://hawkphoenix.blogsp...
*

Please read https://www.hyakkendana-hashigozake.com.org/wiki/ZKDeveloper%27sReference/Integration/Persistence_Layer/Hibernate




See more: Panasonic Tv Blinking Red Light 10 Times, Panasonic, Repairing Led Blinking 10 Or 2 Times On Th

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!