-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Composite Identifier code example please!!
PostPosted: Tue Jan 31, 2006 7:30 am 
Newbie

Joined: Fri Jan 27, 2006 7:52 am
Posts: 3
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 31, 2006 10:49 am 
Newbie

Joined: Fri Jan 27, 2006 7:52 am
Posts: 3
I have managed to sort this ClassCastException (the id class was of the wrong type) but still have an issue.

The code works fine if the database is empty, but if there is an existing row in the database I get the following error:

org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update

14:35:48,796 ERROR JDBCExceptionReporter:72 - ORA-01407: cannot update ("ADVISOR"."CF_OC_LIST"."Value_Pack_Id") to NULL

The question is this:
Why is a call to createCriteria().add().list() causing hibernate to do an UPDATE?
Why is the ID null if in the database, the ID field is set?

I think I am missing something obvious!

Any pointers appreciated.

Cheerio,
Nic.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.