-->
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: CGLIB ClassCastException / PropertyAccessException
PostPosted: Thu Jul 07, 2005 3:26 pm 
Newbie

Joined: Thu Jul 07, 2005 1:51 pm
Posts: 15
Hi all,

I tried posting this in another thread but I fear I've mis-named it as I'm not really getting any responses to this particular issue.

I'm getting an exception thrown from my CGLIB-generated class - here's the stack trace from Ant -

Code:
    [junit] org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of net.hatfieldgroup.rampv2.biz.wq.WQSample.setAnalyteID
    [junit]    at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:203)
    [junit]    at org.hibernate.tuple.PojoTuplizer.setPropertyValues(PojoTuplizer.java:173)
    [junit]    at org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2919)
    [junit]    at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
    [junit]    at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:530)
    [junit]    at org.hibernate.loader.Loader.doQuery(Loader.java:436)
    [junit]    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
    [junit]    at org.hibernate.loader.Loader.doList(Loader.java:1593)
    [junit]    at org.hibernate.loader.Loader.list(Loader.java:1577)
    [junit]    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
    [junit]    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
    [junit]    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
    [junit]    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
    [junit]    at net.hatfieldgroup.rampv2.test.TestWQAnalyte.testGetFullList(TestWQAnalyte.java:37)
    [junit]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [junit]    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    [junit]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    [junit]    at java.lang.reflect.Method.invoke(Unknown Source)
    [junit]    at junit.framework.TestCase.runTest(TestCase.java:154)
    [junit]    at junit.framework.TestCase.runBare(TestCase.java:127)
    [junit]    at junit.framework.TestResult$1.protect(TestResult.java:106)
    [junit]    at junit.framework.TestResult.runProtected(TestResult.java:124)
    [junit]    at junit.framework.TestResult.run(TestResult.java:109)
    [junit]    at junit.framework.TestCase.run(TestCase.java:118)
    [junit]    at junit.framework.TestSuite.runTest(TestSuite.java:208)
    [junit]    at junit.framework.TestSuite.run(TestSuite.java:203)
    [junit]    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:297)
    [junit]    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeInVM(JUnitTask.java:1072)
    [junit]    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:682)
    [junit]    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:1434)
    [junit]    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:632)
    [junit]    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
    [junit]    at org.apache.tools.ant.Task.perform(Task.java:364)
    [junit]    at org.apache.tools.ant.Target.execute(Target.java:341)
    [junit]    at org.apache.tools.ant.Target.performTasks(Target.java:369)
    [junit]    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
    [junit]    at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
    [junit]    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
    [junit]    at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
    [junit]    at org.apache.tools.ant.Main.runBuild(Main.java:668)
    [junit]    at org.apache.tools.ant.Main.startAnt(Main.java:187)
    [junit]    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
    [junit]    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
    [junit] Caused by: net.sf.cglib.beans.BulkBeanException: net.hatfieldgroup.rampv2.biz.wq.WQAnalyte$$EnhancerByCGLIB$$b20220ef
    [junit]    at net.hatfieldgroup.rampv2.biz.wq.WQSample$$BulkBeanByCGLIB$$1ec8c312.setPropertyValues(<generated>)
    [junit]    at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:200)
    [junit]    ... 42 more
    [junit] Caused by: java.lang.ClassCastException: net.hatfieldgroup.rampv2.biz.wq.WQAnalyte$$EnhancerByCGLIB$$b20220ef
    [junit]    ... 44 more


The code for my WQSample class:

Code:
package net.hatfieldgroup.rampv2.biz.wq;

import net.hatfieldgroup.rampv2.db.*;
import java.sql.Timestamp;

public class WQSample
{
   private Long sampleID;
   private Timestamp samplingDate;
   private String siteID;
   private Long analyteID;
   private double detectionLimit;
   private String resultQualifier;
   private double result;
   private String lab;
   private String analyticalMethod;

   public Long getSampleID(){
      return sampleID;
   }

   public Timestamp getSamplingDate(){
      return samplingDate;
   }

   public String getSiteID(){
      return siteID;
   }

   public Long getAnalyteID(){
      return analyteID;
   }

   public double getDetectionLimit(){
      return detectionLimit;
   }

   public String getResultQualifier(){
      return resultQualifier;
   }

   public double getResult(){
      return result;
   }

   public String getLab(){
      return lab;
   }

   public String getAnalyticalMethod(){
      return analyticalMethod;
   }

   public void setSampleID(Long sampleID){
      this.sampleID = sampleID;
   }

   public void setSamplingDate(Timestamp samplingDate){
      this.samplingDate = samplingDate;
   }

   public void setSiteID(String siteID){
      this.siteID = siteID;
   }

   public void setAnalyteID(Long analyteID){
      this.analyteID = analyteID;
   }

   public void setDetectionLimit(double detectionLimit){
      this.detectionLimit = detectionLimit;
   }

   public void setResultQualifier(String resultQualifier){
      this.resultQualifier = resultQualifier;
   }

   public void setResult(double result){
      this.result = result;
   }

   public void setLab(String lab){
      this.lab = lab;
   }

   public void setAnalyticalMethod(String analyticalMethod){
      this.analyticalMethod = analyticalMethod;
   }
};


The mapping for WQSample:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

   <class name="net.hatfieldgroup.rampv2.biz.wq.WQSample" table="WQSAMPLE">
      <id name="sampleID" column="sampleID" type="java.lang.Long">
         <generator class="native" />
      </id>
      <property name="samplingDate" type="java.sql.Timestamp" />
      <property name="detectionLimit" type="double" />
      <property name="resultQualifier" type="java.lang.String" />
      <property name="result" type="double" />
      <property name="lab" type="java.lang.String" />
      <property name="analyticalMethod" type="java.lang.String" />
      <many-to-one name="analyteID" class="net.hatfieldgroup.rampv2.biz.wq.WQAnalyte" column="analyteID"/>
<!--   <many-to-one name="siteID" class="net.hatfieldgroup.rampv2.biz.wq.WQSite" column="siteID"/> -->
   </class>

</hibernate-mapping>


And the mapping for WQAnalyte:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

   <class name="net.hatfieldgroup.rampv2.biz.wq.WQAnalyte" table="WQANALYTE">
      <id name="analyteID" column="analyteID" type="java.lang.Long">
         <generator class="native" />
      </id>
      <property name="analyteName" type="java.lang.String" />
      <property name="analyteCategory" type="java.lang.String" />
      <property name="units" type="java.lang.String" />
      <property name="abbreviation" type="java.lang.String" />
      <set name="samples" cascade="all" inverse="false" lazy="true">
         <key column="sampleID" />
         <one-to-many class="net.hatfieldgroup.rampv2.biz.wq.WQSample" />
      </set>
   </class>

</hibernate-mapping>


I've tried changing all the java.lang.Long values to primitive longs, then to primitive ints, and neither change makes any difference.

I've also checked the DB to make sure there are no null values in any of the referenced columns, and there aren't.

Not sure what else to do here, this is proving very hard to debug because I can't find any references to this problem actually being resolved on this site or on google, although it looks like it IS a common problem.

If anyone has any ideas they'd be much appreciated, my app is basically stuck broken at this point.


Top
 Profile  
 
 Post subject: Re: CGLIB ClassCastException / PropertyAccessException
PostPosted: Thu Jul 07, 2005 5:27 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
contec wrote:
Hi all,

I tried posting this in another thread but I fear I've mis-named it as I'm not really getting any responses to this particular issue.

I'm getting an exception thrown from my CGLIB-generated class - here's the stack trace from Ant -
...
...
I've tried changing all the java.lang.Long values to primitive longs, then to primitive ints, and neither change makes any difference.

I've also checked the DB to make sure there are no null values in any of the referenced columns, and there aren't.

Not sure what else to do here, this is proving very hard to debug because I can't find any references to this problem actually being resolved on this site or on google, although it looks like it IS a common problem.

If anyone has any ideas they'd be much appreciated, my app is basically stuck broken at this point.


ok, now we're getting somewhere. This is actually pretty easy to recognize now that you've supplied all of the information.

in your WQSample mapping, you have defined the following:
Code:
<many-to-one name="analyteID" class="net.hatfieldgroup.rampv2.biz.wq.WQAnalyte" column="analyteID"/>


However, in your WQSample.java file, you have defined analyteID as a java.lang.Long. You either need to change the property in WQSample.java to be of type net.hatfieldgroup.rampv2.biz.wq.WQAnalyte - as defined in the mapping file, or change the mapping file so that analyteID is a simple <property> mapping.

Code:
<property name="analyteID" column="analyteID" type="long"/>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 6:11 pm 
Newbie

Joined: Thu Jul 07, 2005 1:51 pm
Posts: 15
Perfect, that's fixed it. I was assuming that Hibernate was just pulling the PK of the associated object in, but obviously I should have been assuming that i'd get the whole object.

Thanks for your help.


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.