[RESOLVIDO] - Erro no auto relacionamento bidirecional - Hibernate

4 respostas
giuliasousa

Bom dia, pessoal,

estou tentando mapear um auto relacionamento e recebo o seguinte erro: Error creating bean with name 'transactionManager' defined in file [G:\dev\ws\smartbiz\WEB-INF\src\springConfig.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 file [G:\dev\ws\smartbiz\WEB-INF\src\springConfig.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z

Alguém tem alguma idéia do que pode ser?

Classe UIComponent:
@OneToMany
	@Fetch(FetchMode.SUBSELECT)
	@Cascade( { org.hibernate.annotations.CascadeType.MERGE,
		org.hibernate.annotations.CascadeType.SAVE_UPDATE })			
	public Set<UIComponent> children = new HashSet<UIComponent>();

	@ManyToOne
	public UIComponent parent;

springConfig.xml

...
<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
		destroy-method="destroy">

		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect
				</prop>
				<prop key="hibernate.connection.url">jdbc:postgresql://localhost:5432/smartbiz
				</prop>
				<prop key="hibernate.connection.driver_class">org.postgresql.Driver
				</prop>
				<prop key="hibernate.connection.username">--
				</prop>
				<prop key="hibernate.connection.password">--
				</prop>
				<prop key="hibernate.connection.autocommit">false
				</prop>

				<!--Ehcache Configs-->
				<prop key="hibernate.cache.use_query_cache">false</prop>
				<prop key="hibernate.cache.use_second_level_cache">true</prop>
				<prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider
				</prop>
				<prop key="hibernate.generate_statistics">true</prop>
				<prop key="hibernate.cache.use_structured_entries">true</prop>
				<prop key="hibernate.cache.region_prefix" />
				<prop key="net.sf.ehcache.configurationResourceName">ehcache.xml</prop>
				<prop key="hibernate.cache.provider_configuration_file_resource_path">ehcache.xml</prop>

				<!--configuration pool via c3p0-->
				<prop key="c3p0.acquire_increment">5</prop>
				<prop key="c3p0.idle_test_period">10000</prop>

				<!--seconds-->
				<prop key="c3p0.max_size">30</prop>
				<prop key="c3p0.max_statements">5000</prop>
				<prop key="c3p0.min_size">5</prop>
				<prop key="c3p0.timeout">10000000</prop>

				<!--
					thread is the short name for
					org.hibernate.context.ThreadLocalSessionContext and let Hibernate
					bind the session automatically to the thread
				-->
				<prop key="current_session_context_class">thread</prop>

				<!--this will show us all sql statements-->
				<prop key="hibernate.show_sql">false</prop>

				<!--this will create the database tables for us-->
				<prop key="hibernate.hbm2ddl.auto">update</prop>
				<prop key="hibernate.max_fetch_depth">4</prop>
				<prop key="hibernate.default_batch_fetch_size">50</prop>

			</props>
		</property>

		<property name="annotatedClasses">
			<list>

			<!-- Mappings for all entities -->
                </property>
</bean>
...

4 Respostas

Hebert_Coelho

Você adicionou todas as bibliotecas nas versões necessárias? java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z

Esse erro indica que pode ter uma biblioteca errada.

giuliasousa

Então, Hebert,

na verdade não estão atualizadas. As versões das bibliotecas que tenho são:

hibernate3.5.6
hibernate-commons-annotations-3.2.0
hibernate-jpa-2.0-api-1.0.0
hibernate-jpamodelgen-1.0.0
hibernate-tools-3.2.3.GA
ejb3-persistence
springframework3.1.1

Como é um projeto um tanto grande e o hibernate e spring são gerenciados por um framework interno, o impacto para atualizar as bibliotecas não é tão pequeno, essa realmente seria a única forma de solucionar o problema?

Obrigada (=

Hebert_Coelho

Tem alguma biblioteca aí que realmente não contém o OneToMany e deveria ter com o OrphanRemoval.

Eu imagino que é a hibernate3.5.6

Não sei se essas aí são todas necessárias.

Vamos ver se alguém aqui sabe. ^^

giuliasousa

Realmente o erro era mesmo a versão do hibernate, migramos para a 3.6.1 e deu certo. Valeu Hebert

Criado 2 de outubro de 2012
Ultima resposta 2 de out. de 2012
Respostas 4
Participantes 2