@Transactional(Transactional.TxType.SUPPORTS) and access propertie with @ManyToOne(fetch = FetchType.LAZY) #50203
Unanswered
danieltche
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone.
I have the class below:
The Entity returned by repository.findByIdOptional(id); has a "@manytoone(fetch = FetchType.LAZY)" relationship to another entity.
After calling the method "repository.findByIdOptional(id)", there is no database connection open ( agroal_active_count=0 ). But after calling " mapper.toModel()", a database connection is opened (agroal_active_count = 1.0) and it remains open..
What is the best solution in this case? Should I change the transaction type to REQUIRED, or should I re-implement the findByIdOptional method with a join?
Another question: is it possible set some property so that an error is throw when I try to access a LAZY relationship outside a transaction? I worked with Jboss 7.4 and in that case the getter of a property with LAZY would return null.
Beta Was this translation helpful? Give feedback.
All reactions