-
1. Re: Not understanding detached entities and merge()
mazz Feb 14, 2007 8:53 PM (in response to smokingapipe)The behavior you are seeing with "merge" is correct. It takes a detached entity and merges it into the DB.
-
2. Re: Not understanding detached entities and merge()
smokingapipe Feb 14, 2007 9:13 PM (in response to smokingapipe)So what do I want to use to re-attach a detached entity? I think in Hibernate I would use session.refresh(entity). What would it be in EJB3?
-
3. Re: Not understanding detached entities and merge()
mazz Feb 15, 2007 12:11 AM (in response to smokingapipe)You do as you originally said - that is, use find() to load in the entity and fill in that attached entity with the data coming in from that detached pojo.
There isn't much you can do because the detached pojo you are getting is half-full (i.e. missing that transient data). It has some data but not all of it; but the JPA container doesn't know what is "right" and what is "wrong" with respect to the contents of your detached pojo (since a null collection is clearly a valid thing to have - the container doesn't know if that's what you really want or not). The merge(), therefore, is going to assume the detached pojo getting merged is "full" - that is, it has the correct state for the entire entity.