hibernate postgres存在多对一映射问题

hibernate postgres存在多对一映射问题,hibernate,postgresql,Hibernate,Postgresql,我在生成“创建表”sql时遇到了hibernate映射的问题属性sid是字符串类型,但在数据库中生成表acl\u条目后,它变成了整数类型。我不知道为什么。这导致了如下错误: org.postgresql.util.PSQLException: ERROR: insert or update on table "acl_entry" violates foreign key constraint "id" Detail: Key (sid)=(0) is not present in tabl

我在生成“创建表”sql时遇到了hibernate映射的问题属性sid是字符串类型,但在数据库中生成表acl\u条目后,它变成了整数类型。我不知道为什么。这导致了如下错误:

org.postgresql.util.PSQLException: ERROR: insert or update on table "acl_entry"
violates foreign key constraint "id"
  Detail: Key (sid)=(0) is not present in table "acl_sid".
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryEx
ecutorImpl.java:2157).
感谢您的帮助

这是我的密码:

AclEntry.java:

@Id
@SequenceGenerator(name="aclentry_identifier_seq", sequenceName="aclentry_identifier_seq", allocationSize=1)
@GeneratedValue(strategy = GenerationType.AUTO, generator="aclentry_identifier_seq")
@Column(name = "id", insertable=false, updatable=false)
private Integer id;



@ManyToOne(fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "sid", nullable = false)
@ForeignKey(name = "id")
private AclSid aclSid;


public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}
AclSid.java:

@Id
    @SequenceGenerator(name="aclsid_identifier_seq", sequenceName="aclsid_identifier_seq", allocationSize=1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="aclsid_identifier_seq")
    @Column(name = "id", insertable=false, updatable=false)
    private Integer id;



    @Column(name = "sid")
    private String sid;


    public Integer getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
我的问题是:在生成acl_条目之后,其字段“sid”的类型是整数,而不是预期的字符串。这会导致在生成后将密钥(sid)=(0)更改为0

表acl\u条目生成为:

mask integer,
  acl_object_identity integer,
  sid integer NOT NULL
谢谢你的阅读。

而不是

@ManyToOne(fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "sid", nullable = false)
@ForeignKey(name = "id")
private AclSid aclSid;
尝试设置

@ManyToOne(fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "sid", nullable = false, referencedColumnName = "id")
private AclSid aclSid;
manytone
JoinColumn
是JPA注释。
ForeignKey
是一个特定于Hibernate的注释,我个人从未使用过它,所以很可能你也不需要:)

谢谢Zoltan。但我的问题是:在生成acl_条目之后,其字段“sid”的类型是整数,而不是预期的字符串。这导致生成后密钥(sid)=(0)。您的
@ForeignKey
表示您正在引用
id
列,而不是
sid
,它是一个整数。