I have very simple application in spring including 1 model class for db table, 1 jpa repository class 1 service and 1 controller class.
My service class is:
@Transactional
@Service
public class SomeService {
private ServiceRepository serviceRepository;
@Autowired
public serviceService(ServiceRepository serviceRepository) {
this.serviceRepository = serviceRepository;
}
public void getServiceById(Long id) {
Model model = serviceRepository.getOne(id);
return....
}
}
It is working with @Transactional annotation. But if i delete that i get
org.hibernate.LazyInitializationException: could not initialize proxy
What if i dont want any transactional method or class, Why do i have to make it transactional?