-
1. Re: merge failed (Unknown entity: ... $$EnhancerByCGLIB$$ )
silviu.marcu Nov 14, 2005 3:55 PM (in response to silviu.marcu)I know I try to merge the same object twice.. (once when I merge the A the cascade persist will merge also the B, and also I call the merge secondary in some other method...) but this is permitted by the specification... it should do nothing second time
-
2. Re: merge failed (Unknown entity: ... $$EnhancerByCGLIB$$ )
silviu.marcu Nov 15, 2005 1:18 PM (in response to silviu.marcu)any help ??
-
3. Re: merge failed (Unknown entity: ... $$EnhancerByCGLIB$$ )
patrick_ibg Nov 15, 2005 8:09 PM (in response to silviu.marcu)What is your call to merge? Perhaps you are passing objectA.getClass() instead of A.class?
-
4. Re: merge failed (Unknown entity: ... $$EnhancerByCGLIB$$ )
silviu.marcu Nov 16, 2005 8:33 AM (in response to silviu.marcu)no, the call to merge is
a1 = manager.merge(a)
where a is a detached instance of A, and a has a collection of B (lazy initialized)
now the a1(that is an instance of A) contains the loaded relations...
and after that somewhere after that call it is called the
manager.merge(an instance of B from the a1 relations)
(example manager.merge((B)a1.getBs().iterator().next())
... this last call merge crashes ... with that exception -
5. Re: merge failed (Unknown entity: ... $$EnhancerByCGLIB$$ )
silviu.marcu Nov 16, 2005 8:35 AM (in response to silviu.marcu)it looks like the manager does not recognize the enhanced class :
MY_ENTITY_CLASS_NAME + $$EnhancerByCGLIB$$b1e5cf42 -
6. Re: merge failed (Unknown entity: ... $$EnhancerByCGLIB$$ )
patrick_ibg Nov 16, 2005 9:46 AM (in response to silviu.marcu)Hrm. Have you tried explicitly getting the B before doing a merge? Something like:
B b = a.getBs().iterator().next() ;
B b2 = em.merge (b) ; -
7. Re: merge failed (Unknown entity: ... $$EnhancerByCGLIB$$ )
silviu.marcu Nov 16, 2005 10:18 AM (in response to silviu.marcu)the a is not merged ... so the lazy relation is not loaded...
the a.getBs will not work ...
if you mean the conversion ... it is only an example,
--------------------------------------
B b = a.getBs().iterator().next() ;
B b2 = em.merge (b) ;
--------------------------------------
IS the same thing with
--------------------------------------
em.merge((B)a.getBs().iterator().next())
-------------------------------------- -
8. Re: merge failed (Unknown entity: ... $$EnhancerByCGLIB$$ )
patrick_ibg Nov 16, 2005 1:16 PM (in response to silviu.marcu)-------------------------------------- B b = a.getBs().iterator().next() ; B b2 = em.merge (b) ; -------------------------------------- IS the same thing with -------------------------------------- em.merge((B)a.getBs().iterator().next()) --------------------------------------
Right, I did not see the explicit cast.
Anyway, from the looks of the error, what you're trying to merge is a proxy object... NOT an instance of your entity class B.
It's hard to fathom why this is happening w/o seeing your code or the mappings... -
9. Re: merge failed (Unknown entity: ... $$EnhancerByCGLIB$$ )
silviu.marcu Nov 16, 2005 3:29 PM (in response to silviu.marcu)it is not a proxy (the proxy names are : $Proxy...)
it is some enhanced object... -
10. Re: merge failed (Unknown entity: ... $$EnhancerByCGLIB$$ )
silviu.marcu Nov 17, 2005 1:50 PM (in response to silviu.marcu)I found this very strange thing ....
normally the merge operation traverse all the relations marked at CASCADE merge or all.
when I merge my object, the relation is not merged....
the related object instead to become from
b= B (id=249)
a= A$$EnhancerByCGLIB$$b0ad8802 (id=255)
id= 1
name= "b"
into
b1= B (id=275)
a= A (id=276)
id= 1
name= "b"
---------------------
the a relation remains in A$$EnhancerByCGLIB$$
... so it is not traversed by merge ....
does anybody know why ??
I am sure the annotation are correct (merge contained):
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY) -
11. Re: merge failed (Unknown entity: ... $$EnhancerByCGLIB$$ )
silviu.marcu Nov 17, 2005 2:03 PM (in response to silviu.marcu)is there any other condition that blocks the merge operation to merge the related objects ?
-
12. Re: merge failed (Unknown entity: ... $$EnhancerByCGLIB$$ )
silviu.marcu Nov 17, 2005 2:28 PM (in response to silviu.marcu)also I found this in hibernate logs:
DEBUG [org.hibernate.engine.CascadingAction] cascading to merge: test.B
DEBUG [org.hibernate.event.def.DefaultMergeEventListener] ignoring uninitialized proxy
DEBUG [org.hibernate.event.def.DefaultLoadEventListener] loading entity: [test.B#2842]
DEBUG [org.hibernate.event.def.DefaultLoadEventListener] entity proxy found in session cache
DEBUG [org.hibernate.engine.Cascade] done processing cascade ACTION_MERGE for: test.A
DEBUG [org.hibernate.event.def.DefaultLoadEventListener] loading entity: [test.B#2842]
DEBUG [org.hibernate.event.def.DefaultLoadEventListener] entity proxy found in session cache -
13. Re: merge failed (Unknown entity: ... $$EnhancerByCGLIB$$ )
jwynett Dec 1, 2005 12:22 PM (in response to silviu.marcu)I was getting a very similar error when I tried to access objects in a relationship and got an instance with the "EnhancerByCGLIB"
It seems like a very complex issue but appears to be related to whether the relationship is LAZY and whether you have to rely on the EntityManager to load the object for you. It also seems to be connected with crossing multiple session bean boundaries where you implicitly work with different entity managers.
In my case, I had a session bean method that called other session beans to retrieve data and then later update it. Most of my relationships are loaded LAZILY however if I know I want it eager, I use INNER JOIN FETCH in my query. In this case, I loaded a particular entity, DeviceInterface, that was related to an entity, IpAddress, as an N-1. Since I didn't need the IpAddress at the time, I didn't explicitly load it. However, the EntityManager seems to have generated this EnhancerByCGLIB class for it. Later when I ran another query specifically to get this IpAddress, I would get the mapping exception when I tried to do an update. I also had this problem on another entity.
I found three things that avoided the error:
1. Remove the transaction on the outer session bean method. When not in the transaction, all the objects became detached and I always relied on a fresh entity manager.
2. In my initial query, I would use INNER JOIN FETCH to eagerly load all the objects I would need for the entire transaction, even if I didn't need them right away.
3. Make that IpAddress relationship EAGER.
In any case, I got my code to work, however I'm not particularly satisfied with the solution because I would like to understand why this is happening and come up with a general coding strategy that will consistently avoid this problem without also making everything load eagerly. Otherwise, it's a real hit-or-miss situation where I just respond to the error whenever I see it. And I don't particularly like to be in that position.
Jon -
14. Re: merge failed (Unknown entity: ... $$EnhancerByCGLIB$$ )
silviu.marcu Dec 1, 2005 1:36 PM (in response to silviu.marcu)you are perfectly right ... I reached the same conclusions.
It seems it is a bug .... (or I am doing something wrong)
the manager.merge should never leave a relation (that is uninitialized (lazy) and also marked as CASCADE.MERGE) uninitialized ...
But because I could'nt replicate my error case in a simple example I did not post it.