1

我有这个配置问题:

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

4

1 回答 1

5

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

DDL = 数据定义语言

DLL = 动态链接库

于 2013-07-29T17:30:35.150 回答