Eclipse + maven + hibernate-tools 逆向工程错误

Eclipse + maven + hibernate-tools Reverse Engineering error

提问人:user2880516 提问时间:11/16/2023 最后编辑:user2880516 更新时间:11/16/2023 访问量:23

问:

我正在尝试使用 hibernate-tools 套件的逆向工程工具在 PostgreSQL 数据库中生成表的所有模型。

https://www.codejava.net/frameworks/hibernate/java-hibernate-reverse-engineering-tutorial-with-eclipse-and-mysql 遵循了本指南,但是当我运行休眠代码生成器时,它显示此错误:

org.jboss.tools.hibernate.runtime.spi.HibernateException: Table(public.newtable) already has a primary key!
    at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter$2.execute(LazyDatabaseSchemaWorkbenchAdapter.java:132)
    at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63)
    at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:107)
    at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter.readDatabaseSchema(LazyDatabaseSchemaWorkbenchAdapter.java:119)
    at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter.getChildren(LazyDatabaseSchemaWorkbenchAdapter.java:60)
    at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:104)
    at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:219)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

这是 newtable DDL

CREATE TABLE public."newtable" (
    "codiceFiscale" varchar(16) NOT NULL,
    nome varchar(100) NULL,
    cognome varchar(100) NULL,
    email varchar(255) NULL,
    indirizzo varchar(255) NULL,
    "idComune" int4 NULL,
    "idStato" varchar(3) NULL,
    "idProvincia" int4 NULL,
    cap varchar(10) NULL,
    "ruolo" varchar(1) NULL,
    "idAccount" int4 NULL,
    username varchar(100) NULL,
    rup varchar(10) NULL,
    "codice" varchar(20) NULL,
    "codiceNUTS" varchar(20) NULL,
    "codiceStatoExtraUE" varchar(100) NULL,
    "dataAbilitazione" timestamp NULL,
    "dataRegistrazione" timestamp NULL,
    "numeroRinnovo" int4 NULL,
    CONSTRAINT newtable_pk PRIMARY KEY ("codiceFiscale")
);

这就是冬眠.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="hibernate.connection.password">XXXXXXXXXXXXXXXXXXX</property>
        <property name="hibernate.connection.url">jdbc:postgresql://XXX.XXX.XXX.XXX:5432/test</property>
        <property name="hibernate.connection.username">postgres</property>
        <property name="hibernate.default_schema">public</property>
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
    </session-factory>
</hibernate-configuration>

可以毫无问题地处理其他表。 有什么建议吗?

编辑

通过删除 DDL 中表名和列名两边的双引号,凭经验求解

java 逆向工程 hibernate-tools

评论

0赞 Jim Garrison 11/16/2023
您显示的 DDL 是新生成的 DDL 吗?如果是这样,请在源数据库中显示 DDL。
0赞 user2880516 11/16/2023
@JimGarrison是源数据库中的 DDL

答: 暂无答案