Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3
I have many-to-many reletationship between product and performer; I have mapped the table product twice: to BasicProduct and InactiveBasicProduct (that was not my idea - but others call the shots ;-)).
The mapping for InactiveBasicProduct works fine, if I don't add a set for my many-to-many relationship. If I add the set I get an exception seen below. Is this a problem, that the Mapping of BasicProduct already has a set for the many-to-many relationship to performer? Thx
Mapping documents:
Code:
<hibernate-mapping package="com.sonydadc.claudio.hibernate">
<class name="com.sonydadc.claudio.product.beans.InactiveBasicProduct" table="CLAUDIO_PRODUCT" where="active='N'">
<id name="id" column="PRODUCT_ID" type="string"/>
<property name="title" column="PRODUCT_TITLE" type="string" />
<set name="performers" table="CLAUDIO_PRODUCT_PERFORMER" lazy="true">
<key column="PRODUCT_ID" />
<many-to-many column="PERFORMER_ID" class="com.sonydadc.claudio.product.beans.Performer" />
</set>
</class>
</hibernate-mapping>
Code:
public class InactiveBasicProduct implements Serializable {
private static final long serialVersionUID = 8283608851397524224L;
private String id;
private String title;
private String author;
private Set performers;
/**
* @return Returns the id.
*/
public String getId() {
return id;
}
/**
* @param id The id to set.
*/
public void setId(String id) {
this.id = id;
}
/**
* @return Returns the performers.
*/
public Set getPerformers() {
return performers;
}
/**
* @param performers The performers to set.
*/
public void setPerformers(Set performers) {
this.performers = performers;
}
/**
* @return Returns the title.
*/
public String getTitle() {
return title;
}
/**
* @param title The title to set.
*/
public void setTitle(String title) {
this.title = title;
}
}
Code:
public class InactiveProductDAO extends HibernateDaoSupport implements IInactiveProductDAO {
public InactiveBasicProduct getInactiveProduct(String id) {
InactiveBasicProduct prod = (InactiveBasicProduct) this.getHibernateTemplate().get(InactiveBasicProduct.class,id);
return prod;
}
}
Full stack trace of any exception that occurs:org.springframework.orm.hibernate3.HibernateSystemException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.sonydadc.claudio.product.beans.InactiveBasicProduct.setPerformers; nested exception is org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.sonydadc.claudio.product.beans.InactiveBasicProduct.setPerformers
org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.sonydadc.claudio.product.beans.InactiveBasicProduct.setPerformers
at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:197)
at org.hibernate.tuple.PojoTuplizer.setPropertyValues(PojoTuplizer.java:167)
at org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2879)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:452)
at org.hibernate.loader.Loader.doQuery(Loader.java:406)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1255)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:139)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:124)
at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2453)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:387)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:368)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:166)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:140)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:249)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:123)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:561)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:556)
at org.springframework.orm.hibernate3.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:389)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:312)
at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:383)
at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:378)
at com.sonydadc.claudio.product.dao.InactiveProductDAO.getInactiveProduct(InactiveProductDAO.java:42)
at com.sonydadc.claudio.product.unittest.InactiveProductDAOTest.testgetInactiveProduct(InactiveProductDAOTest.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: net.sf.cglib.beans.BulkBeanException
at com.sonydadc.claudio.product.beans.InactiveBasicProduct$$BulkBeanByCGLIB$$6029bd25.setPropertyValues(<generated>)
at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:194)
... 39 more
Caused by: java.lang.ClassCastException
... 41 more
Name and version of the database you are using: Oracle 9i
[/code]