-->
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: Many-to-many mapping problem
PostPosted: Wed Sep 28, 2005 6:30 am 
Newbie

Joined: Mon Sep 05, 2005 8:40 am
Posts: 2
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]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 28, 2005 4:50 pm 
Regular
Regular

Joined: Fri Sep 09, 2005 11:35 am
Posts: 101
does not look like a hibernate problem.
you are getting a ClassCastException in the setter.
Debug the setter and you should be able to find the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 28, 2005 5:24 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
My experience is that following the advice of the exception is very helpful in tracking down the problem:

Quote:
set hibernate.cglib.use_reflection_optimizer=false for more info

_________________
nathan


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.