SpringJPA不创建表SpringMVC

beq87vna  于 2021-09-13  发布在  Java
关注(0)|答案(1)|浏览(272)

我正在开发一个spring mvc应用程序,其中我使用spring jpa创建表并连接到数据库。最初我的jpa正常工作,表也在创建中,但由于一些调试问题,我删除了所有表,当我再次运行api时,它不再创建表,并出现以下错误:

ERROR: relation "clients" does not exist\n  Position: 449
2021-07-27 15:33:50 [@] ERROR GenericControllerAdvice: Exception StackTrace:
org.springframework.orm.jpa.JpaSystemException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
        at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:424) ~[spring-orm-4.3.22.RELEASE.jar:4.3.22.RELEASE]
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:526) ~[spring-orm-4.3.22.RELEASE.jar:4.3.22.RELEASE]

我的jpa配置是:

<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?createDatabaseIfNotExists=true" />
        <property name="username" value="postgres" />
        <property name="password" value="" />

    </bean>
    <bean id="entityManagerFactory"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="packagesToScan" value="com.clients" />
        <property name="dataSource" ref="dataSource" />
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                <prop key="hibernate.ddl-auto">create</prop>
                <prop key="generate-ddl">true</prop>
        </props>
        </property>

我已经创建了测试数据库,它的默认公共模式为1。有人能帮忙吗?谢谢

dkqlctbz

dkqlctbz1#

hibernate属性是错误的。
它必须是:

<props>
    <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
    <prop key="hibernate.hbm2ddl.auto">create</prop>
</props>

相关问题