Hibernate 不使用 HSQL 和 Spring 创建表

Hibernate not creating tables with HSQL and Spring

有人知道为什么 hibernate 在我的示例中没有创建表吗?

这是我的 web.xml - http://pastebin.com/ZaseSaBS

mvc-dispatcher-servlet.xml - http://pastebin.com/LbdxMSAb

applicationContext.xml - http://pastebin.com/bAHMaVNX

控制台日志 - http://pastebin.com/tTZZbxkX

我有一个配置几乎相同的类似项目,在另一个项目上 运行 一切似乎都很好。任何想法为什么它不在这里创建表? 我在 com.calculator.enity 中有一个带有 @Entity @GeneratedValue 注释的测试实体,我将其列在 persistence.xml 文件中。 com.calculator.repository

中还有此实体的 JpaRepository

您的持久性配置似乎没有正确完成。根据您的要求使用此示例持久性配置。这对我来说很好用。

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



    <context:component-scan base-package="com.xxx.xxx"/>
    <tx:annotation-driven />
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactoryBean" />
    </bean>



    <bean id="entityManagerFactoryBean"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="com.xxx.xxx" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
        </property>

        <property name="jpaProperties">
            <props>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
            </props>
        </property>
    </bean>


    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="org.postgresql.Driver" />
        <property name="url" value="jdbc:postgresql://localhost:5432/test" />
        <property name="username" value="postgres" />
        <property name="password" value="prateek" />
    </bean>
</beans>