【问题标题】:Spring-JPA-Hibernate Configuration: setting property hiberate.hbm2dll.auto to create has no effect?Spring-JPA-Hibernate 配置:设置属性 hiberate.hbm2dll.auto 创建没有效果?
【发布时间】:2013-07-29 14:32:57
【问题描述】:

我有这个配置问题:

1) 我将 jpaPropertyMap 的属性 hibernate.hbm2dll.auto 设置为创建,但它没有效果。它没有创建表生成 SQL。

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

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

那么为什么 hibernate.hbm2dll.auto 在案例/生成表中不起作用。

这是配置文件:

<?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>

使用: 休眠 4.2.2.Final Spring 3.2.3.RELEASE

【问题讨论】:

    标签: spring hibernate jpa configuration


    【解决方案1】:

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

    DDL = 数据定义语言

    DLL = 动态链接库

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-25
      • 2013-04-22
      • 1970-01-01
      • 1970-01-01
      • 2020-08-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多