如果JPA不存在,如何在数据库中创建对象?

2 java persistence hibernate jpa jdbc

我有一个Web应用程序,我使用JPA/Hibernate我想知道如何hibernate可以从实体生成不存在的表.持久性文件如下:

我可以添加什么属性?

<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>
Run Code Online (Sandbox Code Playgroud)

Dav*_* SN 9

您可以添加此属性

<property name="hibernate.hbm2ddl.auto" value="update"/> 
Run Code Online (Sandbox Code Playgroud)

此属性的可能值为:

  • validate:仅验证架构
  • 更新:更新架构
  • create:创建架构,覆盖以前的数据
  • create-drop:创建架构并在会话结束时删除架构