-
1. Re: ManyToOne Unidirectional relationship and merge vs. flush
asookazian Aug 6, 2009 1:32 AM (in response to dhinojosa)Do you have cascade enabled? AFAIK if you are using SMPC then the EntityManager remains open until the LRC ends (which means you need to find out why your entity is being detached from the PC and thus no longer managed by the EntityManager).
The nabble link has examples with cascade settings. Perhaps that's involved in the root cause?
And how does it behave if you have a @ManyToOne bidirectional relationship with or w/o cascading enabled?
-
2. Re: ManyToOne Unidirectional relationship and merge vs. flush
lvdberg Aug 6, 2009 10:49 AM (in response to dhinojosa)Daniel,
It depends a bit how you've defined an entity and their relation. I tend to annotate a Many-to-One relation between two Entities in such a way that I need to persist the other entity first prior to persisting the
many-side
. I always load the One-side prior to persisting the Many-side, so preventing any detached-problem. This is mostly the case in Entity to ValueObjects relations; so the entity should alwaysDB-exist
. Also in Entity-to-Entity I use the same approach, cascading is really nice but I tend to use it only forOwned Collections
(composite aggegrations).Leo
P.S. This is really a Hibernate-question and a fundamental domain-modelling discussion and should be asked in their forum.
-
3. Re: ManyToOne Unidirectional relationship and merge vs. flush
dhinojosa Aug 6, 2009 7:15 PM (in response to dhinojosa)Except the problem in my case is the
one
relationship item is already persisted and managed by entitymanager. -
4. Re: ManyToOne Unidirectional relationship and merge vs. flush
dhinojosa Aug 6, 2009 7:20 PM (in response to dhinojosa)
Arbi Sookazian wrote on Aug 06, 2009 01:32:
Do you have cascade enabled? AFAIK if you are using SMPC then the EntityManager remains open until the LRC ends (which means you need to find out why your entity is being detached from the PC and thus no longer managed by the EntityManager).I have verified that they are attached and I do have cascade enabled.
The nabble link has examples with cascade settings. Perhaps that's involved in the root cause?I just used that as an example, as to the problem I was having.
And how does it behave if you have a @ManyToOne bidirectional relationship with or w/o cascading enabled?I'll find out. Although I don't want bidirection since that would just make my User bean a mess. ;)
-
5. Re: ManyToOne Unidirectional relationship and merge vs. flush
dhinojosa Aug 6, 2009 8:15 PM (in response to dhinojosa)Corrected, In a reference of a reference of reference I used an entity loaded from the session entity manager, instead of LRC entity manager. Thanks everyone.