当我在生成“create table”sql时遇到了hibernate映射的问题。 属性sid是字符串类型,但是在数据库中生成表acl_entry后它变为整数类型。我不知道为什么。这导致了这样的错误:hibernate postgres多对一映射问题
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_ENTRY后,其场 “SID” 是如预期的那样,整数类型不是字符串。这导致生成后的密钥(sid)=(0)。
mask integer,
acl_object_identity integer,
sid integer NOT NULL
感谢阅读:
表ACL_ENTRY作为生成。
你的'@ ForeignKey'表明你引用'id'列,而不是' sid',这是一个整数。 –