【发布时间】:2013-07-16 17:45:30
【问题描述】:
我有一个使用 JPA / Hibernate 的 Web 应用程序我想知道如何休眠可以从实体生成不存在的表。 持久化文件如下:
我可以添加什么作为属性?
<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_1_0.xsd"
version="1.0">
<persistence-unit name="BankingApp">
<provider> org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/>
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:XE"/>
<property name="hibernate.connection.username" value="user"/>
<property name="hibernate.connection.password" value="password"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
</properties>
</persistence-unit>
</persistence>
【问题讨论】:
-
我不确定我是否明白你的问题。如何从不存在的实体生成表?您希望它生成所有可能的表吗?
-
@JohnAment 不,我希望从实体生成表
-
您是否在问如果没有类的实例退出,hibernate 如何生成表?或者如果不存在类定义(带有实体注释/映射)?
-
@user2264997 我想创建实体类和表将在构建后生成。即生成表格形式实体
-
默认情况下,hibernate 可以在部署时执行此操作,hibernate.hbm2ddl.auto 带有值、创建、更新等。这将自动应用于连接。 hibernate 工具也支持将其输出到文件,请参阅docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/…
标签: java hibernate jpa jdbc persistence