-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Spring Hibernate JPA causing DuplicateMappingException
PostPosted: Thu Mar 05, 2009 5:20 am 
Newbie

Joined: Wed Mar 04, 2009 2:42 am
Posts: 2
Location: Malaysia
Hi, is there anyone know this problem? I am currently integrating JPA using Spring and Hibernate in order to access EntityManager.merge(...). By default, I was included session factory (including hibernate hbm xml mapping) and HibernateDaoSupport which provided by Spring feature. However, because I integrate with ZK, which force to include the hibernate session merge converter which is required the merge the entity to resolved the "lazy initialization exception". To include this merging, I utilize on EJB, JPA, and Spring IoC which will describe in the following:


persistence.xml
...
<persistence-unit name="persistenceManager" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence </provider>
</persistence-unit>
</persistence>
...


jpa context xml:

...
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityMana gerFactoryBean"></bean>

<!-- bean post-processor for JPA annotations -->
<bean class="org.springframework.orm.jpa.support.Persist enceAnnotationBeanPostProcessor" />

<!-- Exception translation bean post processor -->
<bean class="org.springframework.dao.annotation.Persiste nceExceptionTranslationPostProcessor"/>

<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionM anager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<tx:annotation-driven />
...


HibernateSessionMergeConverter:
...

@Stateless
public class HibernateSessionMergeConverter implements TypeConverter {

@PersistenceContext
private EntityManager em;

public Object coerceToUi(Object val, Component comp) {

if(val instanceof GenericBean){
System.out.println(em==null);
em.merge(val);
}
return val;
}
...

However, it throws "DuplicateMappingException" because of duplication. I tried with alot of way and even to confirm that my hbm xml and bean have no duplication of fields.

The following is the exception thrown:

org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExc eptionTranslationPostProcessor#0' defined in ServletContext resource [/WEB-INF/resources/xml/jpaApplicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/resources/xml/jpaApplicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: org.hibernate.DuplicateMappingExceptio
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:478)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 64)
at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:220)
at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:261 )
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.context.support.AbstractApplic ationContext.getBean(AbstractApplicationContext.ja va:881)
at org.springframework.context.support.AbstractApplic ationContext.registerBeanPostProcessors(AbstractAp plicationContext.java:597)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:366)
at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:255)
at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 45)
at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:3764)
at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4216)
at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase.java:760)
at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:740)
at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:544)
at org.apache.catalina.startup.HostConfig.deployDescr iptor(HostConfig.java:626)
at org.apache.catalina.startup.HostConfig.deployDescr iptors(HostConfig.java:553)
at org.apache.catalina.startup.HostConfig.deployApps( HostConfig.java:488)
at org.apache.catalina.startup.HostConfig.start(HostC onfig.java:1149)
at org.apache.catalina.startup.HostConfig.lifecycleEv ent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLife cycleEvent(LifecycleSupport.java:120)
at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1022)
at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:736)
at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1014)
at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:443)
at org.apache.catalina.core.StandardService.start(Sta ndardService.java:448)
at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:700)
at org.apache.catalina.startup.Catalina.start(Catalin a.java:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootst rap.java:295)
at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:433)
Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/resources/xml/jpaApplicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: org.hibernate.DuplicateMappingException: Duplicate collection role mapping User.riskGroups
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1336)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:471)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 64)
at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:220)
at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:261 )
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeansOfType(DefaultListableB eanFactory.java:308)
at org.springframework.beans.factory.BeanFactoryUtils .beansOfTypeIncludingAncestors(BeanFactoryUtils.ja va:270)
at org.springframework.dao.support.PersistenceExcepti onTranslationInterceptor.detectPersistenceExceptio nTranslators(PersistenceExceptionTranslationInterc eptor.java:122)
at org.springframework.dao.support.PersistenceExcepti onTranslationInterceptor.<init>(PersistenceExcepti onTranslationInterceptor.java:78)
at org.springframework.dao.annotation.PersistenceExce ptionTranslationAdvisor.<init>(PersistenceExceptio nTranslationAdvisor.java:70)
at org.springframework.dao.annotation.PersistenceExce ptionTranslationPostProcessor.setBeanFactory(Persi stenceExceptionTranslationPostProcessor.java:97)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1324)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:471)
... 38 more


Your help and kindness is highly appreciated


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.