使用Glassfish 4和Postgres在eclipselink中无法创建数据库

编程入门 行业动态 更新时间:2024-10-26 09:21:01
本文介绍了使用Glassfish 4和Postgres在eclipselink中无法创建数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想基于实体创建数据库.配置:

I want to create the database based on Entities. Configuration:

  • Glassfish:GlassFish Server开源版4.1(内部版本13)
  • Eclipselink:Eclipse Persistence Services-2.5.2.v20140319-9ad6abd(与Glassfish一起提供)
  • 数据库:PostgreSQL版本:9.4.2
  • 驱动程序:PostgreSQL本机驱动程序版本:PostgreSQL 9.4 JDBC4.1(内部版本1201)
  • 从eclipselink开始创建数据库的那一刻起,在将许多日志参数置于最佳状态之后,我在日志中看到以下语句:

    From the moment eclipselink starts creating the database I see the following statements in the logs after putting a lot of log parameters on finest:

    • 从表名中选择ID,其中WHERE ID<> ID
    • 选择1
    • 重复4-5次.第一个查询给出以下明显的postgres错误:

      This is repeated 4-5 times. The first query gives the following obvious postgres error:

      org.postgresql.util.PSQLException:错误:关系"table_name"不存在位置:16

      org.postgresql.util.PSQLException: ERROR: relation "table_name" does not exist Position: 16

      结果,以下查询给出以下错误:

      As a result a following queries give the following error:

      org.postgresql.util.PSQLException:错误:当前事务已中止,命令被忽略,直到事务块结束

      org.postgresql.util.PSQLException: ERROR: current transaction is aborted, commands ignored until end of transaction block

      此eclipselink之后,继续创建表:

      After this eclipselink continues creating the tables:

      创建表table_name(ID BIGINT不为NULL,主键(ID))

      CREATE TABLE table_name (ID BIGINT NOT NULL, PRIMARY KEY (ID))

      但是会产生相同的错误.

      But produces the same error.

      由于某种原因,在事务中创建数据库.我发现源代码负责,但是我找不到交易如何开始.我可以提供更详细的信息,但也许现在有人已经可以提供帮助了.

      For some reason creating the database happens in a transaction. I found the source code responsible, but I can't find out how the transaction is started. I can give more detailed information, but maybe somebody can already help now.

      persistence.xml

      The persistence.xml

      <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="java.sun/xml/ns/persistence" xmlns:xsi="www.w3/2001/XMLSchema-instance" xsi:schemaLocation="h ttp://java.sun/xml/ns/persistence java.sun/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name="AntennasOperatingSystemServerPU" transaction-type="RESOURCE_LOCAL"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <non-jta-data-source>MyDatabase</non-jta-data-source> <class>... bunch of classes ... </class> <exclude-unlisted-classes>true</exclude-unlisted-classes> <properties> <property name="eclipselink.logging.level" value="ALL"/> <property name="eclipselink.logging.logger" value="org.eclipse.persistence.logging.DefaultSessionLog"/> <property name="eclipselink.deploy-on-startup" value="true"/> <property name="eclipselink.ddl-generation.output-mode" value="database"/> <property name="eclipselink.logging.level.sql" value="FINEST"/> <property name="eclipselink.ddl-generation" value="create-tables"/> <property name="eclipselink.target-database" value="PostgreSQL" /> </properties> </persistence-unit> </persistence>

      推荐答案

      我前段时间做了类似的事情.以下配置可以正常工作.

      I did something similar some time ago. The following configuration work well.

      <persistence-unit name="EjemploJpaPU" 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:derby://localhost:1527/example"/> <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/> <property name="javax.persistence.jdbc.user" value="root"/> <property name="javax.persistence.jdbc.password" value="123"/> <property name="eclipselink.logging.level" value="ALL"/> <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> </properties> </persistence-unit>

      很显然,一旦创建了表,就有必要将属性 eclipselink.ddl-generation 的值更改为 none .

      Obviously, once the tables are created, it is necessary to change the value of the property eclipselink.ddl-generation to none.

      注意:数据库是Derby,但我也在MySQL上尝试过.我认为它将与PostgreSQL一起使用.

更多推荐

使用Glassfish 4和Postgres在eclipselink中无法创建数据库

本文发布于:2023-10-15 11:58:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1494276.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   Glassfish   Postgres   eclipselink

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!