Hi,
I have a problem with composite id, it tries to insert composite id's parts into db. Code is as follows:
--------------------------------------------------------------------------
Entity:
Code:
@Entity
@Table(name = "LOV_SET_ELEM")
@IdClass(LovSetElementPK.class)
public class LovSetElement implements Serializable {
private static final long serialVersionUID = -5088707631626664039L;
@Id
@Column(name = "NLOVSETID", insertable = false, updatable = false)
private long lovSetId;
@Id
@Column(name = "NLOVID", insertable = false, updatable = false)
private long lovId;
@ManyToOne
@JoinColumn(name = "NLOVSETID")
private LovSet lovSet;
@OneToOne
@JoinColumn(name = "NLOVID")
private GenericLov lov;
public LovSetElement() {
}
public LovSetElement(LovSet lovSet, GenericLov lov) {
this.lovSetId = lovSet.getId();
this.lovSet = lovSet;
System.out.println(lov.getId());
this.lovId = lov.getId();
this.lov = lov;
}
public long getLovSetId() {
return lovSetId;
}
public void setLovSetId(long lovSetId) {
this.lovSetId = lovSetId;
}
public long getLovId() {
return lovId;
}
public void setLovId(long lovId) {
this.lovId = lovId;
}
public LovSet getLovSet() {
return lovSet;
}
public void setLovSet(LovSet lovSet) {
this.lovSet = lovSet;
}
public GenericLov getLov() {
return lov;
}
public void setLov(GenericLov lov) {
this.lov = lov;
}
}
--------------------------------------------------------------------------
PK:
Code:
public class LovSetElementPK implements Serializable {
private static final long serialVersionUID = 3685792951484393301L;
private long lovSetId;
private long lovId;
public LovSetElementPK() {
}
public LovSetElementPK(long lovSetId, long lovId) {
this.lovSetId = lovSetId;
this.lovId = lovId;
}
public long getLovSetId() {
return lovSetId;
}
public void setLovSetId(long lovSetId) {
this.lovSetId = lovSetId;
}
public long getLovId() {
return lovId;
}
public void setLovId(long lovId) {
this.lovId = lovId;
}
@Override
public boolean equals(Object o) {
return ((o instanceof LovSetElementPK)
&& lovSetId == ((LovSetElementPK) o).getLovSetId() && lovId == ((LovSetElementPK) o)
.getLovId());
}
@Override
public int hashCode() {
return (int) (lovSetId + lovId);
}
}
--------------------------------------------------------------------------
and after:
LovSetElement lse = new LovSetElement(lovSet, lov);
em.persist(lse);
where both lovSet and lov are valid objects i get:
Code:
Hibernate:
/* insert mrted.domain.lovhierarchy.LovSetElement
*/ insert
into
mtu1142.LOV_SET_ELEM
(NLOVID, NLOVSETID, lovId, lovSetId)
values
(?, ?, ?, ?)
16:21:28,175 WARN JDBCExceptionReporter:100 - SQL Error: 904, SQLState: 42000
16:21:28,176 ERROR JDBCExceptionReporter:101 - ORA-00904: "LOVSETID": invalid identifier
Why those two additional colums ? there is insertable = false etc..... what's wrong with my code ?
Thanks in advance,
Tom