[RESOLVIDO] Problema com Hibernate e Spring 3

Boa Noite, Pessoal!

Estou dessenvolvendo uma aplicação com Hibernate 3.6 e Spring 3.1.

No mapeamento das entidades do banco estava usando o seguinte:

<property name="mappingResources">
	<list>
		<value>entity/hibernate/Cargo.hbm.xml</value>
		<value>entity/hibernate/Funcionario.hbm.xml</value>
		<value>entity/hibernate/Pessoa.hbm.xml</value>
	</list>
</property>

Aí passei para classes com annotations:

<property name="annotatedClasses">
	<list>
	        <value>br.com.application.entity.Cargo</value>
		<value>br.com.application.entity.Funcionario</value>
		<value>br.com.application.entity.Pessoa</value>
	</list>
</property>

Só que o seguinte erro é retornado:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/classes/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?
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1396)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
	... 55 more
Caused by: 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?
	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1064)
	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:924)
	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1393)

Abaixo segue meu applicationContext.xml:


<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:ws="http://jax-ws.dev.java.net/spring/core"
	   xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       					   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
                           http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
                           http://jax-ws.dev.java.net/spring/core http://jax-ws.dev.java.net/spring/core.xsd
						   http://jax-ws.dev.java.net/spring/servlet http://jax-ws.dev.java.net/spring/servlet.xsd"
	   default-autowire="byName" >


    <bean id="propertyPlaceholder"
              class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="ignoreUnresolvablePlaceholders" value="false"/>
            <property name="ignoreResourceNotFound" value="false"/>
            <property name="order" value="1"/>
            <property name="locations">
                <list>
                    <value>classpath:hibernate_mysql.properties</value>
					<value>classpath:settings.properties</value>
				</list>
            </property>
    </bean>


	<bean id="dataSource"
		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName" value="${db1.hibernate.connection.driver_class}" />
		<property name="url" value="${db1.hibernate.connection.url}" />
		<property name="username" value="${db1.hibernate.connection.username}" />
		<property name="password" value="${db1.hibernate.connection.password}" />
	</bean>

	<bean id="sessionFactory"
		  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource">
			<ref local="dataSource" />
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">${db1.hibernate.dialect}</prop>
				<prop key="hibernate.show_sql">${db1.hibernate.show_sql}</prop>
				<prop key="hibernate.hbm2ddl.auto">${db1.hibernate.hbm2ddl.auto}</prop>
				<prop key="hibernate.cache.provider_class">${db1.hibernate.cache.provider_class}</prop>
				<prop key="hibernate.cache.use_query_cache">${db1.hibernate.cache.use_query_cache}</prop>
				<prop key="hibernate.max_fetch_depth">${db1.hibernate.max_fetch_depth}</prop>
				<prop key="hibernate.proxool.pool_alias">PoolDb1</prop>
				<prop key="hibernate.jdbc.batch_versioned_data">${db1.hibernate.jdbc.batch_versioned_data}</prop>
				<prop key="hibernate.jdbc.use_streams_for_binary">${db1.hibernate.jdbc.use_streams_for_binary}</prop>
				<prop key="hibernate.c3p0.max_size">${db1.hibernate.c3p0.max_size}</prop>
				<prop key="hibernate.c3p0.max_size">${db1.hibernate.c3p0.max_size}</prop>
				<prop key="hibernate.c3p0.min_size">${db1.hibernate.c3p0.min_size}</prop>
				<prop key="hibernate.c3p0.timeout">${db1.hibernate.c3p0.timeout}</prop>
				<prop key="hibernate.c3p0.max_statements">${db1.hibernate.c3p0.max_statements}</prop>
				<prop key="hibernate.c3p0.idle_test_period">${db1.hibernate.c3p0.idle_test_period}</prop>
				<prop key="hibernate.c3p0.acquire_increment">${db1.hibernate.c3p0.acquire_increment}</prop>
			</props>
		</property>
		<property name="annotatedClasses">
			<list>
				<value>br.com.application.entity.Cargo</value>
				<value>br.com.application.entity.Funcionario</value>
				<value>br.com.application.entity.Pessoa</value>
			</list>
		</property>
	</bean>

	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>

	<tx:annotation-driven transaction-manager="transactionManager"/>
	
	<context:annotation-config/> 
	<context:component-scan base-package="com.versioneye" />	

	<bean id="secureService"
		class="org.ploin.utils.service.impl.SecureService"
		lazy-init="false">
		<property name="min" value="5" />                             <!-- Mindenstlaenge -->
		<property name="max" value="20" />                            <!-- Maximallaenge -->
		<property name="mustContainSmallCharacters" value="false" />  <!-- muessen Kleinbuchstaben im Passwort enthalten sein -->
		<property name="mustContainBigCharacters" value="false" />    <!-- muessen Grossbuchstaben im Passwort enthalten sein -->
		<property name="mustContainNumbers" value="false" />          <!-- muessen Zahlen im Passwort enthalten sein -->
		<property name="mustContainSpecialSign" value="false" />      <!-- muessen Sonderzeichen im Passwort enthalten sein -->
	</bean>

</beans>

Que falha cometi para gerar esse erro?

Agradeço desde já pela ajuda.

Valeu!

Como você pretende mudar de estrutura de configuração baseada em XML sem alterar a classe do Spring que identifica as entities mapeadas?
Veja que nesta linha, você utiliza org.springframework.orm.hibernate3.LocalSessionFactoryBean

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
        <property name="sessionFactory" ref="sessionFactory" />  
    </bean>  

Este cara só consegue ler mapeamento em XML.
Se você trocar por org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean, vai funcionar.

Olá, drsmachado!

Fiz a alteração que você falou, mas agora deu esse erro:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IncompatibleClassChangeError: Implementing class
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
	... 55 more
Caused by: java.lang.IncompatibleClassChangeError: Implementing class
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(Unknown Source)
	at java.security.SecureClassLoader.defineClass(Unknown Source)
	at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2901)
	at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1170)
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
	at java.lang.Class.getDeclaredConstructors0(Native Method)
	at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
	at java.lang.Class.getConstructor0(Unknown Source)
	at java.lang.Class.getDeclaredConstructor(Unknown Source)
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104)
	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newConfiguration(LocalSessionFactoryBean.java:779)
	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:561)
	at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:134)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
	... 62 more

O que pode ser?

Valeu…

Segundo http://stackoverflow.com/questions/10474976/java-lang-incompatibleclasschangeerror-implementing-class-mongo pode ser incompatibilidade de versões de algum jar.
Você está usando todos os jars compatíveis com a versão que indica (hibernate 3.6 e spring 3.1) e o driver do banco de dados é compatível com o que está utilizando?

drsmachado,

Percebi aqui umas bibliotecas do hibernate 3.3 e retirei elas, deixando só as do hibernate 3.6 aí funfou legal.

Obrigado pela ajuda.

Valeu…