2013-03-25 24 views
0

你好,我想遷移的Hibernate 3.6.3應用到Hibernate 4,我收到以下錯誤:遷移,Hibernate的3.6.3-JPA應用到Hibernate 4

Invalid property 'dataSource' of bean class 
[org.springframework.orm.jpa.LocalEntityManagerFactoryBean]: 
Bean property 'dataSource' is not writable or has an invalid 
setter method. Does the parameter type of the setter match the 
return type of the getter? 

我已經看了這個帖子: integrating JPA and SpringIOc

當我使用LocalEntityManagerFactoryBean負責我得到上面提到的錯誤,但是當我使用LocalContainerEntityManagerFactoryBean我創造我的DAO bean時得到一個錯誤。

我認爲這是spring.orm依賴配置的問題,但我不確定,因爲我所做的所有依賴項更改都不起作用。

我在哪裏可以找到Hibernate 4遷移指南,以適應我的JPA,Hibernate 3.6.3和Spring應用程序?

+0

春季版本中使用 – 2013-03-25 12:26:40

+0

我想你可能必須使用' LocalContainerEntityManagerFactoryBean'而不是'LocalEntityManagerFactoryBean' – 2013-03-25 12:29:09

回答

2

按照Documentation

This EntityManagerFactory bootstrap is appropriate for standalone applications which solely use JPA for data access. If you want to set up your persistence provider for an external DataSource and/or for global transactions which span multiple resources, you will need to either deploy it into a full Java EE 5 application server and access the deployed EntityManagerFactory via JNDI, or use Spring's LocalContainerEntityManagerFactoryBean with appropriate configuration for local setup according to JPA's container contract.

這意味着你可能需要使用LocalContainerEntityManagerFactoryBean代替LocalEntityManagerFactoryBean

<bean id="entityManager" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
    <property name="dataSource" ref="myDataSource" /> 
    .... 
    .... 
</bean> 

例:

+0

如果我使用LocalContainer EntityManagerFactoryBean我得到:創建名爲'entityManagerFactory'的bean時出錯... java.lang.NoClassDefFoundError:org/hibernate/util/xml/Origin ... org.springframework.beans.factory.BeanCreationException – amartin 2013-03-25 12:48:40

+0

這是hibernate和spring的版本使用 – 2013-03-25 12:57:44

+0

我的應用程序使用Hibernate 3.6.3,但現在我已將hibernate-core依賴項更改爲版本4.17 – amartin 2013-03-25 13:30:25

相關問題