-->
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.  [ 3 posts ] 
Author Message
 Post subject: Association (Gavin can you help me with this)
PostPosted: Mon Feb 09, 2004 6:21 am 
Beginner
Beginner

Joined: Fri Jan 23, 2004 5:08 am
Posts: 21
Hi. i've follow the instructions in this link http://forum.hibernate.org/old//717844.html.

I have 3 tables, Contact, Industry and ContactIndustry(holds the association of contact and industry).Using the example from the said link it works fine.

But my ContactIndustry has only two fields, contact_id and industry_id so i think creating a contactindustry class is redundant.

Here's what i did.

Contact.java
{
long id = 0;
Set industries = null;
}

Industry.java
{
long id = 0;
}


<class name="com.eon.cms.vo.Contact" table="contact">
<id name="id" type="long" unsaved-value="0">
<generator class="native"/>
</id>

<set name="industries" table="contact_industry" >
<key column="contact_id"/>
<composite-element class="com.eon.cms.vo.Contact">
<many-to-one name="industry" column="industry_id" class="com.eon.cms.vo.Industry" not-null="true" cascade="all"/>
</composite-element>
</set>
</class>

save the object using the following code

Contact contact = new Contact();
contact.setName("Raymond");

Industry industry = .........
Set industrySet = new HashSet();
industrySet.add(industry);
contact.setContactIndustry(industrySet);
contact.setSector(sector);
.......
session.save(contact)


prompts me this error:


java.lang.ClassCastException
at com.eon.cms.vo.ContactMetaClass2.getPropertyValues(<generated>)
at net.sf.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:197)
at net.sf.hibernate.type.ComponentType.nullSafeGetValues(ComponentType.java:171)
at net.sf.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:158)
at net.sf.hibernate.collection.CollectionPersister.writeElement(CollectionPersister.java:398)
at net.sf.hibernate.collection.Set.writeTo(Set.java:235)
at net.sf.hibernate.collection.CollectionPersister.recreate(CollectionPersister.java:632)
at net.sf.hibernate.impl.ScheduledCollectionRecreate.execute(ScheduledCollectionRecreate.java:23)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2100)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2065)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2005)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:57)
at com.eon.common.SQLManager$Transaction.run(SQLManager.java:116)
at com.eon.cms.dao.HBMContactDAO.add(HBMContactDAO.java:43)
at com.eon.cms.manager.ContactManager.add(ContactManager.java:32)
at Tester.main(Tester.java:68)
rethrown as net.sf.hibernate.PropertyAccessException: exception getting property value with CGLIB getter of com.eon.cms.vo.Contact.?
at net.sf.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:200)
at net.sf.hibernate.type.ComponentType.nullSafeGetValues(ComponentType.java:171)
at net.sf.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:158)
at net.sf.hibernate.collection.CollectionPersister.writeElement(CollectionPersister.java:398)
at net.sf.hibernate.collection.Set.writeTo(Set.java:235)
at net.sf.hibernate.collection.CollectionPersister.recreate(CollectionPersister.java:632)
at net.sf.hibernate.impl.ScheduledCollectionRecreate.execute(ScheduledCollectionRecreate.java:23)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2100)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2065)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2005)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:57)
at com.eon.common.SQLManager$Transaction.run(SQLManager.java:116)
at com.eon.cms.dao.HBMContactDAO.add(HBMContactDAO.java:43)
at com.eon.cms.manager.ContactManager.add(ContactManager.java:32)
at Tester.main(Tester.java:68)
Caused by: java.lang.ClassCastException
at com.eon.cms.vo.ContactMetaClass2.getPropertyValues(<generated>)
at net.sf.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:197)
... 14 more

i think am missing something in the composite-element. need your help guys

thanks..


raymond


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 09, 2004 6:22 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Read the documentation, "many-to-many" associations.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 09, 2004 6:33 am 
Beginner
Beginner

Joined: Fri Jan 23, 2004 5:08 am
Posts: 21
wow it works... thank you very much


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.