带有postgresql投掷的春季应用程序“ psqlexception:错误:不存在运算符:cartare = uuid;

发布于 2025-02-12 15:43:58 字数 2008 浏览 2 评论 0 原文

我有一个看起来像这样的实体:

import lombok.*;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.util.List;
import java.util.UUID;

@Entity(name = "EnterpriseGroup")
@Data
@EqualsAndHashCode
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Table(name = "enterprise_groups")
public class EnterpriseGroup {

    @Id
    @GeneratedValue(generator = "uuid4")
    @GenericGenerator(name = "UUID", strategy = "uuid4")
    @Type(type = "pg-uuid")
    @Column(columnDefinition = "CHAR(36)")
    private UUID groupId;

    @Column(unique = true)
    private String name;

    private String description;

    @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST})
    @JoinTable(
            name = "groups_roles",
            joinColumns = {@JoinColumn(name = "groupId")},
            inverseJoinColumns = {@JoinColumn(name = "roleId")})
    private List<UserRole> roles;
}

我有一个默认的JPA存储库:

import com.fadata.security.domain.entities.EnterpriseGroup;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.UUID;

@Repository
public interface EnterpriseGroupRepository extends JpaRepository<EnterpriseGroup, UUID> {
}

当我尝试调用 repository.findall()方法时,我会得到以下例外:

o.h.engine.jdbc.spi.SqlExceptionHelper: could not extract ResultSet [n/a]
org.postgresql.util.PSQLException: ERROR: operator does not exist: character = uuid

Hint: No operator matches the given name and argument types. You might need to add explicit type casts.

我尝试更改UUID类型和发电策略,列定义和名称,到目前为止什么都没有。我尝试通过在存储库方法上放置断点来调试它,但是它永远不会受到打击,这意味着在该方法击中该方法之前有某种验证,这也是此问题的起源。我敢肯定,我通过有效的UUID,因为如果我通过无效的UUID格式,就会抛出适当的例外。然而,我得到的例外使我认为我通过请求转换并击中实际应用程序的UUID的方式存在某种问题。欢迎任何想法!谢谢!

I have an entity that looks like this:

import lombok.*;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.util.List;
import java.util.UUID;

@Entity(name = "EnterpriseGroup")
@Data
@EqualsAndHashCode
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Table(name = "enterprise_groups")
public class EnterpriseGroup {

    @Id
    @GeneratedValue(generator = "uuid4")
    @GenericGenerator(name = "UUID", strategy = "uuid4")
    @Type(type = "pg-uuid")
    @Column(columnDefinition = "CHAR(36)")
    private UUID groupId;

    @Column(unique = true)
    private String name;

    private String description;

    @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST})
    @JoinTable(
            name = "groups_roles",
            joinColumns = {@JoinColumn(name = "groupId")},
            inverseJoinColumns = {@JoinColumn(name = "roleId")})
    private List<UserRole> roles;
}

I have a default JPA Repository:

import com.fadata.security.domain.entities.EnterpriseGroup;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.UUID;

@Repository
public interface EnterpriseGroupRepository extends JpaRepository<EnterpriseGroup, UUID> {
}

When I try calling repository.findAll() method, I get the following exception:

o.h.engine.jdbc.spi.SqlExceptionHelper: could not extract ResultSet [n/a]
org.postgresql.util.PSQLException: ERROR: operator does not exist: character = uuid

Hint: No operator matches the given name and argument types. You might need to add explicit type casts.

I've tried changing up the UUID type and generation strategies, the column definitions and name, and nothing has worked so far. I tried debugging it by putting a breakpoint on the repository method, but it is never hit, meaning there is some kind of validation that goes on before the method is hit, and that's where this issue originates from. I'm certain I'm passing a valid UUID, because a proper exception is thrown if I pass an invalid UUID format. Yet the exception I get makes me think there is some kind of issue with the way the UUID I pass in with the request is converted and hits the actual app. Any ideas are welcome! Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

惜醉颜 2025-02-19 15:43:59

尝试一下 uuidchartype

@Id
@Type(type = "org.hibernate.type.UUIDCharType")
@GeneratedValue(generator = "UUID")
@GenericGenerator(
        name = "UUID",
        strategy = "org.hibernate.id.UUIDGenerator"
)
@Column(name = "groupId", updatable = false, nullable = false)
private UUID groupId;

注意:不需要通过uuid.randomuuid()

Try it UUIDCharType link

@Id
@Type(type = "org.hibernate.type.UUIDCharType")
@GeneratedValue(generator = "UUID")
@GenericGenerator(
        name = "UUID",
        strategy = "org.hibernate.id.UUIDGenerator"
)
@Column(name = "groupId", updatable = false, nullable = false)
private UUID groupId;

Note: not need generate UUID by UUID.randomUUID()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文