Basically I'm trying to get an entity that has a LAZY relation to another entity. Below are 2 things I tried. The first one works, the second one does not and I don't understand why. All I want is to get the entity from database. The reason why I put this in other method is I don't want the first one to be @Transactional because it can take some time to execute. Note that I'm not saving or even accessing the database again in the first method, I just need to read from db once.
Method 1 (Works as expected):
@Override
@Transactional
public void sendEmailToUser(Long exhibitorId) {
EmailExhibitorTO exhibitorTO = findExhibitorById(exhibitorId);
}
private EmailExhibitorTO findExhibitorById(Long id){
return converter.convert(exhibitorRepository.findById(id), EmailExhibitorTO.class);
}
Everything here is fine, I'm getting the entity and the lazy initialized entity as well.
Method 2 (Doesn't work):
@Override
public void sendEmailToUser(Long exhibitorId) {
EmailExhibitorTO exhibitorTO = findExhibitorById(exhibitorId);
}
@Transactional
private EmailExhibitorTO findExhibitorById(Long id){
return converter.convert(exhibitorRepository.findById(id), EmailExhibitorTO.class);
This however does not work. Error:
There's a mapping exception but that's because lazy entity could not be fetched.
I'm probably just being stupid but if theres something I don't understand, please explain.
Thanks in advance.