Skip to content

LazyInitializationExceptionin template #22

@destan

Description

@destan

<div th:text="${#request.getAttribute(requestAttributeName)}">

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]

Sample code

@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;

}

in controller:

		model.addAttribute("customers", customerRepository.findAll());

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions