I am getting the error: javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process 'merge' call, even though I have the annotated the method with Spring's @Transactional.
Roel De Nijs wrote:Is there any reason why you don't inject the EntityManager like this? Then you could use em in the upload() method. More info about how the Spring @Transactional annotation works, can be found in this article.
Hope it helps!
Kind regards,
Roel
Roel De Nijs wrote:
Rj Ewing wrote:When I inject the EntityManager like that, it is null. I'll take a look at the link. Thanks
You could try the following instead
Roel De Nijs wrote:
Rj Ewing wrote:That is essentially what I am doing, just in upload() and not the constructor.
And what happens if you create the entity manager in the constructor?
Rj Ewing wrote:the getLazilyLoadedData() call
Roel De Nijs wrote:
Rj Ewing wrote:the getLazilyLoadedData() call
And I assume the lazy loaded data was not yet loaded in the entity you have added on the session. Based on this article, that seems to be the expected behavior of the merge() method. A merge() consists of:
retrieve the entity with the same ID as the detached one passed as argument, copy the state of the detached entity to the attached one, and return the attached entity.
So you'll probably need to do update your entity model and cascade merging using the cascade attribute of the relationship annotation e.g. @OneToOne). Something likeMore info provided in this article.
Rj Ewing wrote:When you call manager.merge(myEntity), it returns a new entity. I didn't realize this and was calling the old entity. Anyways I've got it working now.
Consider Paul's rocket mass heater. |