Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在没有连接的情况下使用Hibernate 4生成DDL_Java_Postgresql_Hibernate_Maven_Ddl - Fatal编程技术网

Java 在没有连接的情况下使用Hibernate 4生成DDL

Java 在没有连接的情况下使用Hibernate 4生成DDL,java,postgresql,hibernate,maven,ddl,Java,Postgresql,Hibernate,Maven,Ddl,我曾经使用hibernate3 maven插件和hibernate3生成DDL。 自从我切换到Hibernate 4以来,我不能再使用这个插件了 如果不连接到实际的PostgreSQL数据库,我无法找到从映射生成DDL的方法 我尝试了很多东西(包括de.juplo中的hibernate4 maven插件和),但我觉得每个方法都需要一个DB连接 在Hibernate 4中,有没有一种(好的)方法可以在没有连接的情况下生成DDL?我可以通过以下方式生成DDL脚本: <plugin>

我曾经使用hibernate3 maven插件和hibernate3生成DDL。 自从我切换到Hibernate 4以来,我不能再使用这个插件了

如果不连接到实际的PostgreSQL数据库,我无法找到从映射生成DDL的方法

我尝试了很多东西(包括de.juplo中的hibernate4 maven插件和),但我觉得每个方法都需要一个DB连接


在Hibernate 4中,有没有一种(好的)方法可以在没有连接的情况下生成DDL?

我可以通过以下方式生成DDL脚本:

<plugin>
                <groupId>de.juplo</groupId>
                <artifactId>hibernate4-maven-plugin</artifactId>
                <version>1.1.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>export</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <hibernateDialect>org.hibernate.dialect.PostgreSQLDialect</hibernateDialect>

                    <!-- I want generate the schemas for these dialects too, at same time... -->
                    <!-- <hibernateDialect>org.hibernate.dialect.Oracle10gDialect</hibernateDialect> -->
                    <!-- <hibernateDialect>org.hibernate.dialect.SQLServerDialect</hibernateDialect> -->

                    <target>SCRIPT</target>
                </configuration>
            </plugin>

这正是我所尝试的。但我有一个错误:解析JNDI名称[java:comp/env/jdbc/myapp]时出错。我想这是因为我在hibernate.cfg.xml中有这样的内容:
java:comp/env/jdbc/myapp
我想你不需要cfg.xml。。。你的项目是JEE项目吗?是的。我发现绕过此错误的唯一方法是在hibernate.cfg.xml中注释此属性。我已更新了答案。尝试在persistence.xml中设置数据源。另外,您可以发布persistence.xml和hibernate.cfg.xml吗?我没有persistence.xml。通过在hibernate.cfg.xml中注释connection.datasource属性,我成功地绕过了解析JNDI名称[java:comp/env/jdbc/myapp]的错误。相反,我是在构建会话工厂之前做的:
configuration.setProperty(“hibernate.connection.datasource”,“java:comp/env/jdbc/myapp”)现在可以工作了,谢谢。
<?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="primary">
      <jta-data-source>java:jboss/datasources/library.backendDS</jta-data-source>
      <properties>
         <!-- Properties for Hibernate -->
         <property name="hibernate.hbm2ddl.auto" value="validate" />
         <property name="hibernate.show_sql" value="false" />
      </properties>
   </persistence-unit>
</persistence>