Amr Khaled
Amr Khaled

Reputation: 51

hibernate.enable_lazy_load_no_trans is not working

I'm using JPA2.1 and hibernate 4.3.8 and i have configured the presistence.xml to allow lazy loading

i have added

<property name="hibernate.enable_lazy_load_no_trans" value="true" />

into properties section

but i'm still getting LazyInitializtionException, what is the problem ?

Upvotes: 3

Views: 12676

Answers (3)

surya
surya

Reputation: 1

org.hibernate.LazyInitializationException:

Use this in application.properties if u are working with getReferenceById(id) method

spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true

Upvotes: 0

Vlad Mihalcea
Vlad Mihalcea

Reputation: 154120

The hibernate.enable_lazy_load_no_trans is an anti-pattern and you should never use it because a database connection is needed for every lazy association that is fetched outside of the initial Persistence Context, and that's going to put pressure on the underlying transaction log and the JDBC connection pool.

More, the hibernate.enable_lazy_load_no_trans is prone to N+1 query issues.

Sometimes, you don't even need entities, and a DTO projection is even better.

Upvotes: 11

Mr Hoelee
Mr Hoelee

Reputation: 466

Try enter the "true" like this:

<property name="hibernate.enable_lazy_load_no_trans">true</property>

It work for me.

Upvotes: 0

Related Questions