I got the issue with hibernate mapping when generate "create table" sql. The property sid is String type but it becomes integer type after generating table acl_entry in database. And i dont know why. This caused the error like:
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).
Any help is appreciated.
Here is my code:
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;
}
My problem is: after the acl_entry generated, its field "sid" is type of integer not the String as expected. This cause to the key(sid) =(0) after generating.
Table acl_entry generated as:
mask integer,
acl_object_identity integer,
sid integer NOT NULL
Thanks for reading.
@ForeignKeystates that you are referencing theidcolumn, notsid, which is an integer.