Why error occurs Lazy-initialization of the entity?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
45 views
I have entity: Train and Seat. They are connected by the relation one-to-many.

Train
@Entity @Table(name = "train") public class Train { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") private Long id; @Column(name = "name") private String name; @OneToMany(mappedBy = "train", cascade = CascadeType.ALL) private Set seats; ... // Getters and setters


Seat
@Entity @Table(name = "seat") public class Seat { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") private Long id; @Column(name = "carriage") private Integer carriage; @Column(name = "seat") private Integer seat; @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinColumn(name = "train_id", nullable = false) private Train train; ... // Other code


When you try to train I get the error:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.slandshow.models.Train.seats, could not initialize proxy - no Session


What's the problem?
by | 45 views

3 Answers

0 like 0 dislike
You have FetchType.EAGER initialization, not LAZY
by
0 like 0 dislike
Hi! the problem is not lazy initialized, and judging by the error, could not initialize proxy - no Session no session dB connection you have https://examples.javacodegeeks.com/enterprise-java...
by
0 like 0 dislike
Sland Show
Session hibernateutil already died, or do Eager(which is not very horosho).
Either use HB utils something to manage the session.
Either method of service Crees who get this case, make it @Transactional read
then there will be in one Cassie to pass.
If it does not write, let's see
by

Related questions

0 like 0 dislike
3 answers
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
35,390 users