我的配置与Quarkus guide相同。我现在可以从数据库中查询,但是尝试insert会产生此exception。我在使用Eclipselink的JPA中非常有经验,所以我知道Entity类不是问题,因为我可以使用标准的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/

10-11 20:13