java - 如何解决 Quarkus Hibernate 插入 SQLGrammerException

标签 java hibernate quarkus

我的配置与Quarkus指南相同。我现在可以从数据库中查询,但尝试插入会产生此异常。我在使用 Eclipselink 的 JPA 方面非常有经验,所以我知道我的实体类不是问题,因为我可以使用标准 JPQL 语法查询数据库。 插入在简单的 em.persist(entity) 上失败。

javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not insert
Caused by: org.postgresql.util.PSQLException: Unsupported Types value: 1,426,407,511

我的pom.xml:

    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-jdbc-postgresql</artifactId>
    </dependency>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-hibernate-orm</artifactId>
    </dependency>

我的实体代码:

package com.lmco.is3.nc.micro.datasvc.jpa.entity;

import com.lmco.is3.data.uci.NotificationSeverityType;
import com.lmco.is3.data.uci.NotificationStateType;
import com.lmco.is3.nc.micro.datasvc.jpa.converter.PostgresUuidConverter;

import java.io.Serializable;
import java.util.Objects;
import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "ALERT_NOTIFICATION")
@SuppressWarnings("unused")
public class AlertNotificationEntity implements Serializable {

    @Id
    @Convert(converter = PostgresUuidConverter.class)
    @Column(name = "ALERT_NOTIFICATION_UID", nullable = false, updatable = false)
    private UUID alertNotificationUid;

    public UUID getAlertNotificationUid() {
        return alertNotificationUid;
    }

    public void setAlertNotificationUid(UUID alertNotificationUid) {
        this.alertNotificationUid = alertNotificationUid;
    }

    @Convert(converter = PostgresUuidConverter.class)
    @Column(name = "SUBJECT_UID")
    private UUID subjectUid;

    public UUID getSubjectUid() {
        return subjectUid;
    }

    public void setSubjectUid(UUID subjectUid) {
        this.subjectUid = subjectUid;
    }

    /*
    @ElementCollection
    @CollectionTable(name = "ALERT_NOTIF_ENTITY_PERSPECTIVE",
                     joinColumns = @JoinColumn(name = "ALERT_NOTIFICATION_UID", referencedColumnName = "ALERT_NOTIFICATION_UID"))
    @Enumerated(EnumType.ORDINAL)
    @OrderColumn
    @Column(name = "ENTITY_PERSPECTIVE_TYPE")
    private List<EntityPerspectiveType> entityPerspectiveTypes;

    public List<EntityPerspectiveType> getEntityPerspectiveTypes() {
        return entityPerspectiveTypes;
    }

    public void setEntityPerspectiveTypes(List<EntityPerspectiveType> entityPerspectiveTypes) {
        this.entityPerspectiveTypes = entityPerspectiveTypes;
    }
     */

    @Enumerated(EnumType.ORDINAL)
    @Column(name = "NOTIFICATION_STATE")
    private NotificationStateType state;

    public NotificationStateType getState() {
        return state;
    }

    public void setState(NotificationStateType state) {
        this.state = state;
    }

    @Enumerated(EnumType.ORDINAL)
    @Column(name = "NOTIFICATION_SEVERITY")
    private NotificationSeverityType severity;

    public NotificationSeverityType getSeverity() {
        return severity;
    }

    public void setSeverity(NotificationSeverityType severity) {
        this.severity = severity;
    }

    @Column(name = "NOTIFICATION_TIME")
    private double notificationTime;

    public double getNotificationTime() {
        return notificationTime;
    }

    public void setNotificationTime(double notificationTime) {
        this.notificationTime = notificationTime;
    }

    @Convert(converter = PostgresUuidConverter.class)
    @Column(name = "SYSTEM_UID")
    private UUID systemUid;

    public UUID getSystemUid() {
        return systemUid;
    }

    public void setSystemUid(UUID systemUid) {
        this.systemUid = systemUid;
    }

    /*
    @ElementCollection
    @CollectionTable(name = "ALERT_NOTIF_APPLIES_TO_ENTITY",
                     joinColumns = @JoinColumn(name = "ALERT_NOTIFICATION_UID", referencedColumnName = "ALERT_NOTIFICATION_UID"))
    @Convert(converter = PostgresUuidConverter.class)
    @OrderColumn
    @Column(name = "APPLIES_TO_ENTITY_UID")
    private List<UUID> appliesToEntityUids;

    public List<UUID> getAppliesToEntityUids() {
        return appliesToEntityUids;
    }

    public void setAppliesToEntityUids(List<UUID> appliesToEntityUids) {
        this.appliesToEntityUids = appliesToEntityUids;
    }
     */

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        AlertNotificationEntity that = (AlertNotificationEntity) o;
        return Objects.equals(alertNotificationUid, that.alertNotificationUid);
    }

    @Override
    public int hashCode() {
        return Objects.hash(alertNotificationUid);
    }
}

最佳答案

好吧,我解决了自己的问题,比我想象的要简单。 我将 PostresUuidConverter 的用法更改为 @Type(type = "pg-uuid"),现在一切正常。

关于java - 如何解决 Quarkus Hibernate 插入 SQLGrammerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59074323/

相关文章:

java - 如何从 Java 应用程序发出 "top"命令?

java - Hibernate 按属性获取记录不起作用

java - 如何在 Quarkus Tuple.of() 方法中允许超过 6 个参数?

Java - Auth0 JWT 验证 - 这是否正确?

version - Java API找出编译类文件的JDK版本?

java - 如何获取ItemProcessor中当前的资源名称?

java - 为数据库中的唯一名称创建附加 ID?

java - gradle 缺少什么来映射 hibernate ?

spring-boot - Quarkus Jandex 索引无法解析 Artifact org.springframework :spring-web

java - Quarkus kafka 从配置文件设置主题名称