【发布时间】:2015-04-05 08:09:33
【问题描述】:
我有一个使用 jpa+hibernate 的项目。 我有一个 persistence.xml 文件,并希望它自动在数据库中创建表。我已经正确指定了所有属性。 在日志中它显示了所有的 sql 语句,但在数据库中仍然没有表。 有没有人有这个问题的解决方案 我搜索了几乎所有与我的问题相关的链接,但没有任何效果。
这是我的 persistence.xml
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="pl4sms-persistence" >
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.ecomm.pl4sms.persistence.entities.SampleBatch</class>
<class>com.ecomm.pl4sms.persistence.entities.SampleMessage</class>
<properties>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/samplejpa"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="root"/>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="create" />
</properties>
</persistence-unit>
</persistence>
这是我在控制台上得到的
16:35:48,881 INFO [org.hibernate.annotations.common.Version] (ServerService 线程池 -- 23) HCANN000001: Hibernate Commons Annotations {4.0.4.Final} 16:35:49,069 INFO [org.hibernate.dialect.Dialect](ServerService 线程池 -- 23)HHH000400:使用方言:org.hibernate.dialect.H2Dialect 16:35:49,084 WARN [org.hibernate.dialect.H2Dialect](ServerService 线程池 -- 23)HHH000431:无法确定 H2 数据库版本,某些功能可能无法使用 16:35:49,225 INFO [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory](ServerService 线程池 -- 23)HHH000397:使用 ASTQueryTranslatorFactory 16:35:49,537 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService 线程池 -- 23) HHH000227: 运行 hbm2ddl 模式导出
【问题讨论】:
-
你在使用 gui 工具 pgAdmin 来做 postgres
-
是的,我使用 pgAdmin 创建数据库
-
这很奇怪,因为创建查询显示在控制台中,您是否检查了 pgAdmin
PostgreSql->samplejpa->Schemas->public->Tables的表。如果有任何问题,它将显示在控制台中。 -
是的,我确实检查过,但没有表格......我也很困惑为什么它没有被创建
-
你解决过这个问题吗?如果可能的话,我想知道问题是什么以及解决方案。
标签: java hibernate jpa wildfly-8