联合主键配置时忽略的问题composite-id class must implement Serializable

运行程序报错:

Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxxxDao' defined in file [D:\WorkSpace\xxx\xxx\webapp\WEB-INF\classes\com\xxx\xxx\xxx\config\spring-webmanage.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [jar:file:/D:/WorkSpace/xxx/xxx/webapp/WEB-INF/lib/xxx.jar!/spring-base.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException:composite-id class must implement Serializable: com.xxx.xxx.xxx.pojo.Organization
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)

……

 

这一段中,最重要的错误提示是“composite-id class must implement Serializable:

是因为在映射文件.hbm.xml中定义为联合主键,即用<composite-id>

<composite-id>  

   <key-property name="pid" type="java.lang.String">  

         <column name="PID" />  

   </key-property>  

   <key-property name="cid" type="java.lang.String">  

         <column name="CID" />  

   </key-property>  

  </composite-id>

 

解决办法:

使用联合主键时,bean类必须序列化

import java.io.Serializable;

public classBean implements Serializable {

    private static final long serialVersionUID = 1L;

}

 


你可能感兴趣的:(联合主键配置时忽略的问题composite-id class must implement Serializable)