When Spring integrates Hibernate, an error is reported:
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 'annotatedclass' of bean class [org. springframework. orm. hibernate3.LocalSessionFactoryBean]: Bean property 'Annotatedclasse' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
......
The reason is that the sessionFactory of Hibernate has two options:
1. LocalSessionFactoryBean, Which is configured using *. hbm. xml, and the bean class is hibernate3.LocalSessionFactoryBean:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><property name="dataSource" ref="dataSource"></property><property name="mappingResources"><list><value>User.hbm.xml</value></list></property><property name="hibernateProperties"><props><prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </prop></props></property></bean>
2. AnnotationSessionFactoryBean. The bean class is AnnotationSessionFactoryBean.
<bean id="sessionFactory"class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"><property name="dataSource" ref="dataSource" /><property name="annotatedClasses</span>"><list><value>com.xxx.model.User</span></value></list></property><property name="hibernateProperties"><!-- <value>hibernate.dialect=org.hibernate.dialect.HSQLDialect</value> --> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> </props></property></bean>
When obtaining a session, use Session s = sessionFactory. openSession ();