I have two entities in the program
@Entity
@Table(name = "users")
public class User {
@OneToMany(mappedBy = "senderUser")
private List<Message> sentMessages;
@OneToMany(mappedBy = "recipientUser")
private List<Message> receivedMessages;
and
@Entity
@Table(name = "messages")
public class Message {
@ManyToOne
@JoinColumn(name = "sender")
private User senderUser;
@ManyToOne
@JoinColumn(name = "recipient")
private User recipientUser;
As it seems to me, when you download a user during logon, you will be mingled with his message along with these two lists. But I wanted to check it out and just display the size of one of these lists on the screen, because I have 2 messages in the database, while displaying in controller
System.out.println("Length: " + ((User) session.getAttribute("user")).getReceivedMessages().size());
Throws a bug in the browser
Exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.jonki.Entity.User.receivedMessages, could not initialize proxy - no Session
and
Root Cause
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.jonki.Entity.User.receivedMessages, could not initialize proxy - no Session
It looks like there is a problem with the session, but what?