【问题标题】:How to generate tables from entities in Idea 13?如何从 Idea 13 中的实体生成表格?
【发布时间】:2014-10-13 18:06:57
【问题描述】:

我尝试了一下,但找不到选项 JPA>从实体生成表。我来自 eclipse 世界,我可以通过几次点击生成实体或脚本,我发现这在 intellij 中更难做到。

这是我正在使用的 persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="hmdb" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
        <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/hmdb_dev"/>
        <property name="javax.persistence.jdbc.user" value="appsetup"/>
        <property name="javax.persistence.jdbc.password" value="--------"/>
        <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
        <property name="eclipselink.ddl-generation" value="create-tables"/>
        <property name="eclipselink.ddl-generation.output-mode" value="sql-script"/>
        <property name="eclipselink.application-location" value="/home/jhonnytunes/Projects/hmdb/target" />
        <property name="eclipselink.create-ddl-jdbc-file-name" value="create.sql" />
    </properties>
</persistence-unit>
</persistence>

我用来生成文件的位置是想法构建目录。没有办法使用从 eclipselink 页面下载的 eclipselink 作为 zip 文件生成吗?

【问题讨论】:

    标签: eclipse intellij-idea eclipselink


    【解决方案1】:

    您可以在服务器启动时在 persistence.xml 中生成 DDL 脚本:

    <properties>
      <property name="eclipselink.ddl-generation" value="create-tables"/>
      <property name="eclipselink.ddl-generation.output-mode" value="sql-script"/>
      <property name="eclipselink.application-location" value="/sql" />
      <property name="eclipselink.create-ddl-jdbc-file-name" value="create.sql" />
    </properties>
    

    第一个属性的值可以是

    • 创建表
    • 创建或扩展表
    • 删除并创建表

    对于第二个属性

    • 数据库
    • sql脚本
    • 两者都有

    更多信息请参见 eclipselink 文档,例如 herehere

    【讨论】:

    • 今晚我会用tomcat7试试。
    • 它没有用。我重启了tomcat@intellij,找不到任何sql脚本。
    • 抱歉,我以为您想创建表格,而不是脚本。您应该可以使用第二个选项来控制它,我会更新答案
    • 很好,我尝试了该选项,但 xml 中没有文件名属性。我想这就是它不起作用的原因。我今晚再试一次。
    • 好吧希望它有效,我没有IntelliJ所以无法检查,但这些是基本原则。也许位置值 "/sql" 是特定于平台和/或 IDE 的,因此您可能需要对此进行试验
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-23
    • 2017-12-16
    • 1970-01-01
    • 2017-08-06
    • 2016-08-27
    • 2012-04-28
    相关资源
    最近更新 更多