This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

ManyToOne persist fails after migration to OpenJPA  RSS feed

 
Greenhorn
Posts: 5
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
have some odd trobles after migration from hibernate to openjpa
Simple many-to-one relation

Each Answer aggregates Question it belongs to.




workflow: when new user login, new Answer object is created () but aggregated Question object is retrieved from DB and set to Answer manually (suitable for JSF linking). Answer is to be persisted and linked to it's question.

DAO:

stacktrace:
org.apache.openjpa.persistence.EntityExistsException: An object of type "org.apache.openjpa.enhance.com$bsuir$survey$model$Question$pcsubclass" with oid "com.bsuir.survey.model.Question-2" already exists in this context; another cannot be persisted.
FailedObject: org.apache.openjpa.enhance.com$bsuir$survey$model$Question$pcsubclass@15dcfa4
at org.apache.openjpa.kernel.BrokerImpl.checkForDuplicateId(BrokerImpl.java:4752)
at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2441)
at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2362)
at org.apache.openjpa.kernel.SingleFieldManager.persist(SingleFieldManager.java:259)
at org.apache.openjpa.kernel.StateManagerImpl.cascadePersist(StateManagerImpl.java:2894)
at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2457)
at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2280)
at org.apache.openjpa.kernel.DelegatingBroker.persist(DelegatingBroker.java:1021)
at org.apache.openjpa.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:645)
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:597)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:346)
at $Proxy27.persist(Unknown Source)
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:597)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:193)
at $Proxy5.persist(Unknown Source)
at com.bsuir.survey.dao.AnswerDao.createAnswerGroup(AnswerDao.java:24)
...

in case entityManager.merge(answer) :

org.apache.openjpa.persistence.EntityExistsException: Attempt to persist detached object "org.apache.openjpa.enhance.com$bsuir$survey$model$Question$pcsubclass@8da5e9". If this is a new instance, make sure any version and/or auto-generated primary key fields are null/default when persisting.
FailedObject: org.apache.openjpa.enhance.com$bsuir$survey$model$Question$pcsubclass@8da5e9
at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2421)
...

the same code worked fine by hibernate, but openjpa is requared. help !
(createQuery via openjpa still works correct, only persist/merge fail)

 
Vladlen Prohorov
Greenhorn
Posts: 5
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
resolved:

some hardcode because of OpenJPA that enforced not to use detached object in setter.
I still don't understant the necessity of such compication compare to hibernate (where just entityManager.persist(answer) is requared)...
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!