Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Foreign key (FKADC4355E513C75C1:TBL_EVA_INFO [ENTER_ID])) must have same number of columns as the referenced primary key (TBL_EVA [EVA_ID,ENTER_ID])
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1260)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:438)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:383)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:353)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:394)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:736)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:369)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:126)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:69)
at my.test.SpringMain.main(SpringMain.java:15)
Caused by: org.hibernate.MappingException: Foreign key (FKADC4355E513C75C1:TBL_EVA_INFO [ENTER_ID])) must have same number of columns as the referenced primary key (TBL_EVA [EVA_ID,ENTER_ID])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:90)
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:73)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1263)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1170)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:674)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1257)
... 14 more
TBL_EVA_INFO.hbm.xml 是hibernate synchronizer 1.3.9 生成的,
TBL_EVA_INFO.hbm.xml 再用hibernate synchronizer 1.3.9 生成
BaseTblEvaInfo.java TblEvaInfo.java TblEvaInfoPK.javaTBL_EVA_INFO.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" ><hibernate-mapping package="my.entity">
<class
name="TblEvaInfo"
table="TBL_EVA_INFO"
>
<meta attribute="sync-DAO">false</meta>
<composite-id name="Id" class="TblEvaInfoPK">
<key-many-to-one
name="Division"
class="MstDiv"
column="DIVISION"
/>
<key-property
name="FileId"
column="FILE_ID"
type="string"
/>
<key-many-to-one
name="Eva"
class="TblEva"
column="EVA_ID"
/>
<key-many-to-one
name="Enter"
class="TblEva"
column="ENTER_ID"
/>
</composite-id> <property
name="Order"
column="ORDER"
type="java.lang.Short"
not-null="true"
length="5"
/>
<property
name="Title"
column="TITLE"
type="string"
not-null="true"
length="100"
/>
<property
name="Comment"
column="COMMENT"
type="string"
not-null="false"
length="200"
/>
<property
name="File"
column="FILE"
type="binary"
not-null="false"
/>
<property
name="FileName"
column="FILE_NAME"
type="string"
not-null="false"
length="255"
/>
<property
name="Updater"
column="UPDATER"
type="string"
not-null="false"
length="92"
/>
<property
name="Updatetime"
column="UPDATETIME"
type="timestamp"
not-null="false"
length="23"
/>
</class>
</hibernate-mapping>public class TblEvaInfoPK extends BaseTblEvaInfoPK {
private static final long serialVersionUID = 1L;/*[CONSTRUCTOR MARKER BEGIN]*/
public TblEvaInfoPK () {}

public TblEvaInfoPK (
my.entity.MstDiv division,
java.lang.String fileId,
my.entity.TblEva eva,
my.entity.TblEva enter) { super (
division,
fileId,
eva,
enter);
}
/*[CONSTRUCTOR MARKER END]*/
}

解决方案 »

  1.   

    Foreign key (FKADC4355E513C75C1:TBL_EVA_INFO [ENTER_ID])) must have same number of columns as the referenced primary key (TBL_EVA [EVA_ID,ENTER_ID]) 外键TBL_EVA_INFO必须有一些行作为关联引用的主键???
    自己看吧,呵呵
      

  2.   

    在你的表TblEva 中 ,有一个many-to-many 映射出现了问题,问题可能是创建中间table时,出现问题。我也是出现同样的问题,解决了 。