2013-03-25 64 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

相关问题