Bean property 'annotatedClasses' is not writable or has an invalid setter method

在使用Junit测试Hibernate+Spring时,提示如下异常:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [spring/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'annotatedClasses' of bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Bean property 'annotatedClasses' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
原因是,在选择Session工程类时,选择的工厂类与PO映射方式不一致,Hibernate有两个Session工厂:
1、LocalSessionFactoryBean:通过XX.hbm.xml来映射实体类
2、AnnotationSessionFactoryBean:通过注释来映射实体类
选择第一种做Session工厂时,主要通过以下方式添加PO
<mapping resource="com/hibernate/News.hbm.xml"/>
选择第二种做Session工厂时,主要通过以下方式添加PO
<property name="annotatedClasses">
<list>
<value>com.test.entity.TPerson</value>
</list>
</property>

猜你喜欢

转载自michael8335.iteye.com/blog/1556138