Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.example.bootstrap4demo.Customer.address, could not initialize proxy - no Session
at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:602) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:217) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:581) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:148) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.hibernate.collection.internal.PersistentSet.toString(PersistentSet.java:327) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
@Data
@Entity
class Customer {
@Id
@GeneratedValue
private Long id;
private String fullName;
private String username;
@NotBlank
private String email;
private String password;
private LocalDate birthDate;
private Integer age;
private Boolean adult;
@ElementCollection
private Set<String> address;
private Role role;
}
model.addAttribute("customers", customerRepository.findAll());