ERROR LazyInitializationException:42 – failed to lazily initialize a collection of role no session or session was closed org.hibernate.LazyInitializationException


Discount: https://www.udemy.com/spring-framework-4-course-and-core-spring-certification/?couponCode=spring32coupon

19 aug 2015 10:03:24,448 ERROR LazyInitializationException:42 – failed to lazily initialize a collection of role: class, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: class, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:383)
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:375)

Solution on JUnit tests

@Test
@Transactional

And @Entity level use fetch = FetchType.EAGER

@OneToMany(mappedBy = "groups", fetch = FetchType.EAGER)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s