问题描述
hibernate的映射出问题,我是想建立双向的1-N关系,用在Set就可以,但是用List就不行,为什么?而且我用同样的方法对另外的一个双向的1-N关系做List映射是可以的,就是到了这个就不行首先发问题:ERROR11:46:44[ContextLoader:206]-Contextinitializationfailed22766org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:206)org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'org.springframework.context.annotation.internalRequiredAnnotationProcessor':BeanPostProcessorbeforeinstantiationofbeanfailed;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'genericTx':Initializationofbeanfailed;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'cxf'definedinclasspathresource[META-INF/cxf/cxf.xml]:Initializationofbeanfailed;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'org.springframework.transaction.config.internalTransactionAdvisor':Cannotcreateinnerbean'(innerbean)'oftype[org.springframework.transaction.interceptor.TransactionInterceptor]whilesettingbeanproperty'transactionInterceptor';nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'(innerbean)#9':Cannotresolvereferencetobean'transactionManager'whilesettingbeanproperty'transactionManager';nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'transactionManager'definedinURL[file:/F:/workspace/gxyc/WebContent/WEB-INF/classes/applicationContext.xml]:Cannotresolvereferencetobean'sessionFactory'whilesettingbeanproperty'sessionFactory';nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'sessionFactory'definedinURL[file:/F:/workspace/gxyc/WebContent/WEB-INF/classes/applicationContext.xml]:Invocationofinitmethodfailed;nestedexceptionisorg.hibernate.MappingException:Repeatedcolumninmappingforcollection:com.skylink.csms.ycob.model.CallInspectInfo.inspectDetailInfoscolumn:SIDatorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:481)atjava.security.AccessController.doPrivileged(NativeMethod)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170)atorg.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:883)atorg.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:593)atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:351)atorg.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:251)atorg.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:190)atorg.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)atorg.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:551)atorg.mortbay.jetty.servlet.Context.startContext(Context.java:140)atorg.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1341)atorg.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:520)atorg.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:474)atorg.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:42)atorg.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:151)atorg.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:42)atorg.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)atorg.mortbay.jetty.Server.doStart(Server.java:223)atorg.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:42)atorg.mortbay.xml.XmlConfiguration.main(XmlConfiguration.java:982)
解决方案
解决方案二:
Causedby:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'org.springframework.transaction.config.internalTransactionAdvisor':Cannotcreateinnerbean'(innerbean)'oftype[org.springframework.transaction.interceptor.TransactionInterceptor]whilesettingbeanproperty'transactionInterceptor';nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'(innerbean)#9':Cannotresolvereferencetobean'transactionManager'whilesettingbeanproperty'transactionManager';nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'transactionManager'definedinURL[file:/F:/workspace/gxyc/WebContent/WEB-INF/classes/applicationContext.xml]:Cannotresolvereferencetobean'sessionFactory'whilesettingbeanproperty'sessionFactory';nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'sessionFactory'definedinURL[file:/F:/workspace/gxyc/WebContent/WEB-INF/classes/applicationContext.xml]:Invocationofinitmethodfailed;nestedexceptionisorg.hibernate.MappingException:Repeatedcolumninmappingforcollection:com.skylink.csms.ycob.model.CallInspectInfo.inspectDetailInfoscolumn:SIDatorg.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:229)atorg.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:122)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1274)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1042)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485)atjava.security.AccessController.doPrivileged(NativeMethod)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170)atorg.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrievalHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:87)atorg.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:98)atorg.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.findCandidateAdvisors(AnnotationAwareAspectJAutoProxyCreator.java:83)atorg.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:105)atorg.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:290)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:334)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1368)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)...52more
解决方案三:
Causedby:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'(innerbean)#9':Cannotresolvereferencetobean'transactionManager'whilesettingbeanproperty'transactionManager';nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'transactionManager'definedinURL[file:/F:/workspace/gxyc/WebContent/WEB-INF/classes/applicationContext.xml]:Cannotresolvereferencetobean'sessionFactory'whilesettingbeanproperty'sessionFactory';nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'sessionFactory'definedinURL[file:/F:/workspace/gxyc/WebContent/WEB-INF/classes/applicationContext.xml]:Invocationofinitmethodfailed;nestedexceptionisorg.hibernate.MappingException:Repeatedcolumninmappingforcollection:com.skylink.csms.ycob.model.CallInspectInfo.inspectDetailInfoscolumn:SIDatorg.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:274)atorg.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1274)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1042)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485)atjava.security.AccessController.doPrivileged(NativeMethod)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)atorg.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:219)...71moreCausedby:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'transactionManager'definedinURL[file:/F:/workspace/gxyc/WebContent/WEB-INF/classes/applicationContext.xml]:Cannotresolvereferencetobean'sessionFactory'whilesettingbeanproperty'sessionFactory';nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'sessionFactory'definedinURL[file:/F:/workspace/gxyc/WebContent/WEB-INF/classes/applicationContext.xml]:Invocationofinitmethodfailed;nestedexceptionisorg.hibernate.MappingException:Repeatedcolumninmappingforcollection:com.skylink.csms.ycob.model.CallInspectInfo.inspectDetailInfoscolumn:SIDatorg.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:274)atorg.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1274)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1042)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485)atjava.security.AccessController.doPrivileged(NativeMethod)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170)atorg.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:268)...79more
解决方案四:
...100more31406[main]ERRORorg.mortbay.log-Failedstartupofcontextorg.mortbay.jetty.webapp.WebAppContext@1c2e5bb{/gxyc,F:workspacegxycWebContent}org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'org.springframework.context.annotation.internalRequiredAnnotationProcessor':BeanPostProcessorbeforeinstantiationofbeanfailed;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'genericTx':Initializationofbeanfailed;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'cxf'definedinclasspathresource[META-INF/cxf/cxf.xml]:Initializationofbeanfailed;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'org.springframework.transaction.config.internalTransactionAdvisor':Cannotcreateinnerbean'(innerbean)'oftype[org.springframework.transaction.interceptor.TransactionInterceptor]whilesettingbeanproperty'transactionInterceptor';nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'(innerbean)#9':Cannotresolvereferencetobean'transactionManager'whilesettingbeanproperty'transactionManager';nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'transactionManager'definedinURL[file:/F:/workspace/gxyc/WebContent/WEB-INF/classes/applicationContext.xml]:Cannotresolvereferencetobean'sessionFactory'whilesettingbeanproperty'sessionFactory';nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'sessionFactory'definedinURL[file:/F:/workspace/gxyc/WebContent/WEB-INF/classes/applicationContext.xml]:Invocationofinitmethodfailed;nestedexceptionisorg.hibernate.MappingException:Repeatedcolumninmappingforcollection:com.skylink.csms.ycob.model.CallInspectInfo.inspectDetailInfoscolumn:SIDatorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:481)atjava.security.AccessController.doPrivileged(NativeMethod)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
解决方案五:
publicclassInspectDetailInfoimplementsjava.io.Serializable{//Fields/****/privatestaticfinallongserialVersionUID=-2906746596383878133L;privateLongid;//过程ID(主键)privateCallInspectInfocallInspectInfo;//督察单号privateStringinspectIdea;//督察意见privateStringdealMan;//处理人privateDatedealTime;//处理时间publicclassCallInspectInfoimplementsjava.io.Serializable{//Fields/****/privatestaticfinallongserialVersionUID=-1281858414838153032L;privateStringsid;//督察编号privateStringsrcType;//源单类型privateStringsrcId;//源单号privateStringengineNo;//发动机号privateStringcreateMan;//创建人privateDatecreateTime;//创建时间privateStringremindMan;//提醒人privateDateremindTime;//提醒时间privateStringstatus;//状态:0-未完成,2-已完成//privateSetinspectDetailInfos=newHashSet(0);privateList<InspectDetailInfo>inspectDetailInfos=newArrayList<InspectDetailInfo>();
解决方案六:
<?xmlversion="1.0"encoding="utf-8"?><!DOCTYPEhibernate-mappingPUBLIC"-//Hibernate/HibernateMappingDTD3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><!--MappingfileautogeneratedbyMyEclipsePersistenceTools--><hibernate-mapping><classname="com.skylink.csms.ycob.model.InspectDetailInfo"table="SLYC_INSPECT_DETAIL_T"schema="YCCC"><idname="id"type="java.lang.Long"><columnname="ID"precision="22"scale="0"/><generatorclass="com.skylink.common.hibernate.generator.NumberIncrease"/></id><many-to-onename="callInspectInfo"class="com.skylink.csms.ycob.model.CallInspectInfo"fetch="select"><columnname="SID"precision="20"scale="0"/></many-to-one><propertyname="inspectIdea"type="java.lang.String"><columnname="INSPECT_IDEA"length="256"/></property><propertyname="dealMan"type="java.lang.String"><columnname="DEAL_MAN"length="32"/></property><propertyname="dealTime"type="java.util.Date"><columnname="DEAL_TIME"length="7"/></property></class></hibernate-mapping>
解决方案七:
<?xmlversion="1.0"encoding="utf-8"?><!DOCTYPEhibernate-mappingPUBLIC"-//Hibernate/HibernateMappingDTD3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><!--MappingfileautogeneratedbyMyEclipsePersistenceTools--><hibernate-mapping><classname="com.skylink.csms.ycob.model.CallInspectInfo"table="SLYC_CALL_INSPECT_T"><idname="sid"type="java.lang.String"><columnname="SID"length="20"/><generatorclass="com.skylink.common.hibernate.generator.ShortDateIncresment"/></id><propertyname="srcType"type="java.lang.String"><columnname="SRC_TYPE"length="10"/></property><propertyname="srcId"type="java.lang.String"><columnname="SRC_ID"length="20"/></property><propertyname="engineNo"type="java.lang.String"><columnname="ENGINE_NO"length="30"/></property><propertyname="createMan"type="java.lang.String"><columnname="CREATE_MAN"length="20"/></property><propertyname="createTime"type="java.util.Date"><columnname="CREATE_TIME"length="7"/></property><propertyname="remindMan"type="java.lang.String"><columnname="REMIND_MAN"length="20"/></property><propertyname="remindTime"type="java.util.Date"><columnname="REMIND_TIME"length="7"/></property><propertyname="status"type="java.lang.String"><columnname="STATUS"length="2"/></property><listname="inspectDetailInfos"cascade="all"inverse="true"><keycolumn="SID"/><!--多的一方的字段--><indexcolumn="SID"/><!--自己的ID--><one-to-manyclass="com.skylink.csms.ycob.model.InspectDetailInfo"/></list></class></hibernate-mapping>
解决方案八:
关键在这里:Repeatedcolumninmappingforcollection:com.skylink.csms.ycob.model.CallInspectInfo.inspectDetailInfoscolumn:SIDsid被映射到集合,又映射成属性,重复映射了?
解决方案九:
学习了
解决方案十:
引用7楼gdfloyd的回复:
关键在这里:Repeatedcolumninmappingforcollection:com.skylink.csms.ycob.model.CallInspectInfo.inspectDetailInfoscolumn:SIDsid被映射到集合,又映射成属性,重复映射了?
也不是啊,InspectDetailInfo里本来就有SID这个字段,估计是在<listname="inspectDetailInfos"cascade="all"inverse="true"><keycolumn="SID"/><!--多的一方的字段--><indexcolumn="SID"/><!--自己的ID--><one-to-manyclass="com.skylink.csms.ycob.model.InspectDetailInfo"/></list>里<key和<index都是用SID所以是不是系统自己搞混了,就像人脑不知道去找哪个一样。
解决方案十一:
该回复于2011-03-10 15:14:49被版主删除