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