When Spring is integrated with Hibernate, the following error occurs: annotatedClasses is not writable or has an invalid setter method.

Source: Internet
Author: User

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 ();


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.