Hello,
I am looking for example Java code for a composite identifier example - i have the following attempt for creating an object of type CfCustomisation using it's composite key object CfCustomisationId (auto-generated by a Hibernate tool):
Code:
CfCustomisation custom = null;
//customisation uses a composite key
CfCustomisationId cfCustomisationId = new CfCustomisationId(valuePack.getId(), new BigDecimal(Id));
ScrollableResults results = HibernateUtil.getSessionFactory().getCurrentSession().createCriteria(CfCustomisation.class).add( Restrictions.idEq(cfCustomisationId) ).scroll();
if (results!=null)
{
if (results.first())
custom = (CfCustomisation)results.get(0);
}
if (custom==null)
custom = new CfCustomisation();
However, I get an error:
Code:
java.lang.ClassCastException: java.lang.String
at org.hibernate.type.BigDecimalType.getHashCode(BigDecimalType.java:48)
at org.hibernate.type.AbstractType.getHashCode(AbstractType.java:120)
at org.hibernate.engine.EntityKey.getHashCode(EntityKey.java:69)
at org.hibernate.engine.EntityKey.<init>(EntityKey.java:42)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:76)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:889)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:826)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:819)Name: Customisation1
I have looked at:
http://www.hibernate.org/116.html#A23 and yes:
public class CfCustomisationId implements java.io.Serializable
Any further ideas?
Cheerio,
Nic