如何从实体生成表

| 我目前正在使用eclipse jpa工具进行接缝项目;是否可以根据我的实体定义自动生成sql表?如果是这样,我该如何实现?     
已邀请:
这取决于您使用的JPA实现。 使用Hibernate,您可以在
persistence.xml
hibernate.hbm2ddl.auto
属性中指定\'
create
\'或\'
update
\':
<persistence xmlns=\"http://java.sun.com/xml/ns/persistence\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"2.0\">
  <persistence-unit name=\"yourPersistenceUnit\" transaction-type=\"JTA\">
    <description>Your Persistence Unit</description>
    <jta-data-source>java:/DefaultDS</jta-data-source>
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
      <property name=\"hibernate.hbm2ddl.auto\" value=\"create\"/>
      <property name=\"hibernate.show_sql\" value=\"true\"/>
      <property name=\"hibernate.format_sql\" value=\"true\"/>
      <property name=\"hibernate.transaction.flush_before_completion\" value=\"true\"/>
      <property name=\"hibernate.dialect\" value=\"org.hibernate.dialect.HSQLDialect\"/>
    </properties>
  </persistence-unit>
</persistence>
hibernate.hbm2ddl.auto
属性的可能值为:
create
:启动时创建数据库表和索引
create-drop
:在启动时创建数据库表和索引,在关闭时删除
update
:应用程序启动时,检查数据库架构并根据需要进行更新以添加缺少的表和列
validate
:应用程序启动时,检查数据库架构,如果缺少某些表或列,则失败。     

要回复问题请先登录注册