Hi,
I have a java class of the composite key.
Code:
@Embeddable
public class RmInformationItemPK implements Serializable
{
private static final long serialVersionUID = 1L;
@Column(name = "information_item_id")
@GenericGenerator(name = "IdSeq", strategy = "com.kelman.hibernate.VarcharSequenceGenerator",
parameters = { @Parameter(name = "sequence", value = "K_INFORMATION_ITEM_ID_SEQ") })
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "IdSeq")
private String informationItemId;
@Column(name = "info_item_type")
private String infoItemType;
public String getInformationItemId()
{
return informationItemId;
}
public void setInformationItemId(String informationItemId)
{
this.informationItemId = informationItemId;
}
public String getInfoItemType()
{
return infoItemType;
}
public void setInfoItemType(String infoItemType)
{
this.infoItemType = infoItemType;
}
@Override
public int hashCode()
{
return new HashCodeBuilder().append(getInformationItemId())
.append(getInfoItemType()).toHashCode();
}
@Override
public boolean equals(Object obj)
{
if ( !(obj instanceof RmInformationItemPK) ) return false;
RmInformationItemPK castOther = (RmInformationItemPK)obj;
return new EqualsBuilder().append(this.getInformationItemId(), castOther.getInformationItemId())
.append(this.getInfoItemType(), castOther.getInfoItemType())
.isEquals();
}
}
The composite key is called in the object class:
Code:
public class RmInformationItem implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
private RmInformationItemPK pk;
}
When I create an instance of this object, I did:
Code:
RmInformationItemPK infoItemPK = new RmInformationItemPK();
infoItemPK.setInfoItemType("SEIS_TRACE");
RmInformationItem info = new RmInformationItem();
info.setPk(infoItemPK);
session.save(info);
I found that the GenericGenerator didn't get called so that the field "informationItemId" in the class RmInformationItemPK.java has no value.
How to apply the GenericGenerator in a composite key class?
Thanks,