Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

How to persist an entity in EJB3 which

  Asked By: Magenta    Date: Apr 29    Category: Java    Views: 1937
  

Actually i have an entity(lets call it X) which is extending another entity( and lets name it Y ), so basically when i try to persist X the super class (Y) is persisted as well and Y's ID is set as its ID (cause Im using @PrimaryKeyJoinColumn annotation to set its ID which is the same as Y'ID annotation), now im encountering a situation which i have the Y entity and i just need to persist X using the Y's ID.
when i set Y's ID in X and i try to persist it, the error is (which sounds logical !! ):

javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: au.net.netspace.billing.model.AccountPlanServiceFullOptus
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:567)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:192)
at au.net.netspace.persistence.impl.AbstractDAOBean.create(AbstractDAOBean.java:108)
at au.net.netspace.web.business.bean.backing.aconfig.impl.voice.FullVoiceAccountConfigBackingBean.updateAccountPlanServiceFull(FullVoiceAccountConfigBackingBean.java:521)
at au.net.netspace.web.business.bean.backing.aconfig.impl.voice.FullVoiceAccountConfigBackingBeanIntegrationTest.testUpdateAccountPlanServiceFull(FullVoiceAccountConfigBackingBeanIntegrationTest.java:86)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:435)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:356)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:523)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:89)
at org.testng.TestRunner.privateRun(TestRunner.java:622)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:200)
at org.testng.SuiteRunner.run(SuiteRunner.java:126)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:86)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:123)
Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: au.net.netspace.billing.model.AccountPlanServiceFullOptus
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:79)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:620)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:594)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:598)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:186)

and when i try to persist X without setting Id , i receive a new ID.

Do you have any idea how i can handle this problem.( im using EJB3 and Hibernate )

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Jawwad Akram     Answered On: Apr 29

as the exception says you problems is:
"detached entity  passed to persist:"
try to attach your entity first by calling "merge" method of your "EntityManager"

if problem is not solved send the entity definitions and the lines that you are using to persist  the entity.

 
Didn't find what you were looking for? Find more on How to persist an entity in EJB3 which Or get search suggestion and latest updates.




Tagged: