I have the below mentioned Entity classes, when I execute my application I am getting the following exception. Some of the other similar questions didn\'t solve the problem.
The problem is that the scope of your database/JPA transaction only contains the service (which I assume is a stateless session bean) and does NOT contain the REST resource bean.
List
and accesses field empDeptno
.So when Jersey gets the list of Emp
to produce XML out of it, the transaction has already been closed. When now the field empDeptNo
is navigated, JPA tries to lazily load it, which fails as we're already outside a valid transaction/session.
You might try to extend the transaction scope to also contain your Jersey REST resource bean by making a stateless session bean out of it. Then it might be as follows:
List
and accesses field empDeptno
.I'm not 100% sure, it might also be that step 8 comes BEFORE step 7, so the transaction might be closed before the producer does its job. If that's the case, this solution is simply wrong...
But I think you should simply try it...