Spring-JPA-Hibernate配置:设置属性hiberate.hbm2dll.auto创建没有效果? [英] Spring-JPA-Hibernate Configuration: setting property hiberate.hbm2dll.auto to create has no effect?

查看:133
本文介绍了Spring-JPA-Hibernate配置:设置属性hiberate.hbm2dll.auto创建没有效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个配置问题:
$ b $ 1)我有jpaPropertyMap属性hibernate.hbm2dll.auto设置为创建,但它没有效果。它不会创建表生成SQL。

我可以在日志文件中看到其他jpaPropertyMap属性,如方言得到正确设置,因此正在读取属性映射。



2)如果我将HibernateJpaVendorAdapter的属性generateddl设置为true,就会生成表。



为什么hibernate.hbm2dll.auto不能工作case / generated tables。



这是配置文件:

 <?xml version =1.0encoding =UTF-8?> 
< beans xmlns =http://www.springframework.org/schema/beans
xmlns:xsi =http://www.w3.org/2001/XMLSchema-instance
xmlns:context =http://www.springframework.org/schema/context
xmlns:tx =http://www.springframework.org/schema/tx
xsi :schemaLocation =http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework。 org / schema / context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework .ORG /模式/ TX /弹簧-TX-3.2.xsd>

< context:annotation-config />
< context:component-scan base-package =org.demoapps.placementwebsite/>

< bean class =org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor/>

< bean id =dataSourceclass =org.springframework.jdbc.datasource.DriverManagerDataSource>
< property name =driverClassNamevalue =com.mysql.jdbc.Driver/>
< property name =urlvalue =jdbc:mysql:// localhost:3306 / cpm?autoReconnect = true/>
< property name =usernamevalue =user/>
< property name =passwordvalue =password/>
< / bean>

< bean id =entityManagerFactory
class =org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean>
< property name =persistenceUnitNamevalue =punit/>
< property name =dataSourceref =dataSource/>
< property name =jpaVendorAdapter>
< bean class =org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter>
< property name =showSqlvalue =true/>
< / bean>
< / property>

< property name =jpaPropertyMap>
< map>
< entry key =hibernate.dialectvalue =org.hibernate.dialect.MySQL5InnoDBDialect/>
< entry key =hibernate.hbm2dll.autovalue =create/>
< entry key =hibernate.format_sqlvalue =true/>
< / map>
< / property>
< / bean>

< bean id =transactionManagerclass =org.springframework.orm.jpa.JpaTransactionManager>
< property name =entityManagerFactoryref =entityManagerFactory/>
< / bean>

< tx:注解驱动的事务管理器=transactionManager/>
< / beans>

使用:
Hibernate 4.2.2.Final
Spring 3.2.3。 RELEASE

解决方案

属性 hibernate.hbm2ddl.auto ,而不是 hibernate.hbm2dll.auto



DDL =数据定义语言

DLL =动态链接库


I have this configuration problem:

1) I have jpaPropertyMap with property hibernate.hbm2dll.auto set to create but it has no effect. Its not creating table generation SQL.

I can see in log file other jpaPropertyMap property like dialect getting properly set so property map is being read.

2) If i set HibernateJpaVendorAdapter's property generateddl to true, table is being generated.

so why does hibernate.hbm2dll.auto not working in the case/generating tables.

Here is the Configuration file:

<?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:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans       http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">

    <context:annotation-config />
    <context:component-scan base-package="org.demoapps.placementwebsite"/>

    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/cpm?autoReconnect=true" />
        <property name="username" value="user" />
        <property name="password" value="password" />
    </bean>

    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="punit" />
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="true" />
            </bean>
        </property>

        <property name="jpaPropertyMap">
            <map>
                <entry key="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
                <entry key="hibernate.hbm2dll.auto" value="create"/>
                <entry key="hibernate.format_sql" value="true" />
            </map>
        </property>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager" />
</beans>

Using: Hibernate 4.2.2.Final Spring 3.2.3.RELEASE

解决方案

The property is hibernate.hbm2ddl.auto, and not hibernate.hbm2dll.auto.

DDL = Data Definition Language

DLL = Dynamic-Link Library

这篇关于Spring-JPA-Hibernate配置:设置属性hiberate.hbm2dll.auto创建没有效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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