08-02-2023, 01:03 PM
I know it's an old question but I want to help.
You can put the transactional annotation on the service method you need, in this case findTopicByID(id) should have
@Transactional(propagation=Propagation.REQUIRED, readOnly=true, noRollbackFor=Exception.class)
more info about this annotation can be found [here][1]
About the other solutions:
fetch = FetchType.EAGER
is not a good practice, it should be used ONLY if necessary.
Hibernate.initialize(topics.getComments());
The hibernate initializer binds your classes to the hibernate technology. If you are aiming to be flexible is not a good way to go.
Hope it helps
[1]:
You can put the transactional annotation on the service method you need, in this case findTopicByID(id) should have
@Transactional(propagation=Propagation.REQUIRED, readOnly=true, noRollbackFor=Exception.class)
more info about this annotation can be found [here][1]
About the other solutions:
fetch = FetchType.EAGER
is not a good practice, it should be used ONLY if necessary.
Hibernate.initialize(topics.getComments());
The hibernate initializer binds your classes to the hibernate technology. If you are aiming to be flexible is not a good way to go.
Hope it helps
[1]:
[To see links please register here]