Quantcast
Channel: JPA EntityManager: Why use persist() over merge()? - Stack Overflow
Viewing all articles
Browse latest Browse all 17

Answer by logixplayer for JPA EntityManager: Why use persist() over merge()?

$
0
0

I was getting lazyLoading exceptions on my entity because I was trying to access a lazy loaded collection that was in session.

What I would do was in a separate request, retrieve the entity from session and then try to access a collection in my jsp page which was problematic.

To alleviate this, I updated the same entity in my controller and passed it to my jsp, although I imagine when I re-saved in session that it will also be accessible though SessionScope and not throw a LazyLoadingException, a modification of example 2:

The following has worked for me:

// scenario 2 MY WAY// tran startse = new MyEntity();e = em.merge(e); // re-assign to the same entity "e"//access e from jsp and it will work dandy!!

Viewing all articles
Browse latest Browse all 17

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>