Spring数据配置 - 找不到hibernate.properties [英] Spring Data configuration - hibernate.properties not found

查看:87
本文介绍了Spring数据配置 - 找不到hibernate.properties的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Hibernate内存数据库配置Spring Data,基于这个

 < beans xmlns = http://www.springframework.org/schema/beans
xmlns:xsi =http://www.w3.org/2001/XMLSchema-instance
xmlns:jpa =http ://www.springframework.org/schema/data/jpa
xmlns:tx =http://www.springframework.org/schema/tx
xmlns:jdbc =http:/ /www.springframework.org/schema/jdbc
xsi:schemaLocation =http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans /spring-beans.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa-1.0 .xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd

http://www.springframework.org/schema/j dbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd\">

<! - 配置数据源bean - >
< jdbc:embedded-database id =dataSourcetype =HSQL>
< / jdbc:embedded-database>

<! - 为Hibernate创建默认配置 - >
< bean id =hibernateJpaVendorAdapter
class =org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter>
< property name =generateDdlvalue =false>
< / property>
< / bean>

<! - 配置实体管理器工厂bean - >
< bean id =entityManagerFactory
class =org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean>
< property name =dataSourceref =dataSource/>
< property name =jpaVendorAdapterref =hibernateJpaVendorAdapter/>
< property name =persistenceUnitNamevalue =punit/>
< property name =jpaPropertyMap>
< map>
< entry key =hibernate.dialectvalue =org.hibernate.dialect.HSQLDialect>< / entry>
< entry key =hibernate.hbm2ddl.autovalue =create>< / entry>
< entry key =hibernate.show_sqlvalue =true>< / entry>
< / map>
< / property>
< property name =packagesToScanvalue =models/>
< property name =sharedCacheModevalue =ENABLE_SELECTIVE/>
< property name =validationModevalue =NONE/>
< / bean>
< bean id =transactionManager
class =org.springframework.orm.jpa.JpaTransactionManager>
< property name =entityManagerFactoryref =entityManagerFactory/>
< / bean>
< tx:annotation-driven />
< jpa:repositories base-package =beans.repositories/>




但是一遍又一遍我得到:


org.hibernate.cfg.Environment。 HHH000206:找不到hibernate.properties


问题是我不想在 properties 文件,因为我以前没有使用Spring数据,我想将它设置在 xml 配置中,就像我在本文的答案中一样。我错过了什么吗?感谢您的帮助。

该行只不过是来自Hibernate的信息消息。你可能会得到另一个抱怨 hibernate.cfg.xml 的类似问题。

在启动时,hibernate可以使用这两个文件进行配置,而休眠日志记录了这些文件的缺失。没有什么比这更少。你可以简单地忽略它。


I try to configure Spring Data with Hibernate in-memory database, based on this and this answers:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:jdbc="http://www.springframework.org/schema/jdbc"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd

   http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">

<!-- Configure the data source bean -->
<jdbc:embedded-database id="dataSource" type="HSQL">
</jdbc:embedded-database>

<!-- Create default configuration for Hibernate -->
<bean id="hibernateJpaVendorAdapter"
      class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    <property name="generateDdl" value="false">
    </property>
</bean>

<!-- Configure the entity manager factory bean -->
<bean id="entityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/>
    <property name="persistenceUnitName" value="punit"/>
    <property name="jpaPropertyMap">
        <map>
            <entry key="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"></entry>
            <entry key="hibernate.hbm2ddl.auto" value="create"></entry>
            <entry key="hibernate.show_sql" value="true"></entry>
        </map>
    </property>
    <property name="packagesToScan" value="models"/>
    <property name="sharedCacheMode" value="ENABLE_SELECTIVE"/>
    <property name="validationMode" value="NONE"/>
</bean>
<bean id="transactionManager"
      class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven/>
<jpa:repositories base-package="beans.repositories"/>

But over and over again I get:

org.hibernate.cfg.Environment. HHH000206: hibernate.properties not found

Problem is that I don't want to specify it in properties file, as I used to without Spring Data I want to set it in xml configuration, like in answers which I base. Am I missing something? Thank you in advance for every help.

解决方案

That line is nothing more then an information message from Hibernate. You probably get another one similar to this one complaining about hibernate.cfg.xml.

At startup hibernate may be configured using those 2 files and hibernate logs the absence of those. Nothing more nothing less. You can simply ignore it.

这篇关于Spring数据配置 - 找不到hibernate.properties的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆