Hibernate没有使用HSQL和Spring创建表

时间:2016-02-28 00:44:08

标签: java spring hibernate jpa jetty

任何人都知道为什么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

1 个答案:

答案 0 :(得分:2)

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

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