-->
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.  [ 15 posts ] 
Author Message
 Post subject: hibernate.properties and hibernate.cfg.xml
PostPosted: Thu Jul 07, 2005 1:56 pm 
Newbie

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

I'm getting a PropertyAccess exception and the following message: "exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer = false for more info).

I have read that I can't set this value in hibernate.cfg.xml - so I tried creating a hibernate.properties file in /WEB-INF/classes and using that instead - however that results in an error saying my classes are no longer mapped.

In my hibernate.cfg.xml file there are the usual references to all my mapped classes - eg.

<mapping resource="blah/blah/blah.hbm.xml"/>

I assume that because I'm not using the XML file anymore, it's missing this information - how do I specify these values in hibernate.properties?


Top
 Profile  
 
 Post subject: Re: hibernate.properties and hibernate.cfg.xml
PostPosted: Thu Jul 07, 2005 2:00 pm 
Expert
Expert

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

I'm getting a PropertyAccess exception and the following message: "exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer = false for more info).

I have read that I can't set this value in hibernate.cfg.xml - so I tried creating a hibernate.properties file in /WEB-INF/classes and using that instead - however that results in an error saying my classes are no longer mapped.

In my hibernate.cfg.xml file there are the usual references to all my mapped classes - eg.

<mapping resource="blah/blah/blah.hbm.xml"/>

I assume that because I'm not using the XML file anymore, it's missing this information - how do I specify these values in hibernate.properties?


That exception is not talking about the cglib property, it's talking about a property on one of your Objects.

Show the complete stack trace if you want more help.

And yes, you need the <mapping> elements to identify your objects to hibernate. Stick with the hibernate.cfg.xml.


Top
 Profile  
 
 Post subject: Re: hibernate.properties and hibernate.cfg.xml
PostPosted: Thu Jul 07, 2005 2:04 pm 
Newbie

Joined: Thu Jul 07, 2005 1:51 pm
Posts: 15
pksiv wrote:
contec wrote:
Show the complete stack trace if you want more help.


Where do I get this stack trace? I was under the impression that the message to set hibernate.cglib.use_reflection_optimizer = false would give me this stack trace.

I've tried putting try/catch and printStackTrace() inside the setter of my object, but that doesn't seem to do anything.


Top
 Profile  
 
 Post subject: Re: hibernate.properties and hibernate.cfg.xml
PostPosted: Thu Jul 07, 2005 2:06 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
contec wrote:
Where do I get this stack trace? I was under the impression that the message to set hibernate.cglib.use_reflection_optimizer = false would give me this stack trace.

I've tried putting try/catch and printStackTrace() inside the setter of my object, but that doesn't seem to do anything.


Your initial post says
I'm getting a PropertyAccess exception and the following message: "exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer = false for more info).

Is there no stack trace with the PropertyAccess exception ?


Top
 Profile  
 
 Post subject: Re: hibernate.properties and hibernate.cfg.xml
PostPosted: Thu Jul 07, 2005 2:16 pm 
Newbie

Joined: Thu Jul 07, 2005 1:51 pm
Posts: 15
pksiv wrote:
contec wrote:
Where do I get this stack trace? I was under the impression that the message to set hibernate.cglib.use_reflection_optimizer = false would give me this stack trace.

I've tried putting try/catch and printStackTrace() inside the setter of my object, but that doesn't seem to do anything.


Your initial post says
I'm getting a PropertyAccess exception and the following message: "exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer = false for more info).

Is there no stack trace with the PropertyAccess exception ?


There is a stack trace, but it seems to be coming from the CGLIB generated class, not my actual class - meaning that it doesn't do me any good for trying to figure out what's causing the PropertyAccessException.

I assumed this was why it told me to set gibernate.cglib.use_reflection_optimizer = false.


Top
 Profile  
 
 Post subject: Re: hibernate.properties and hibernate.cfg.xml
PostPosted: Thu Jul 07, 2005 2:21 pm 
Expert
Expert

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

There is a stack trace, but it seems to be coming from the CGLIB generated class, not my actual class - meaning that it doesn't do me any good for trying to figure out what's causing the PropertyAccessException.

I assumed this was why it told me to set gibernate.cglib.use_reflection_optimizer = false.


http://www.hibernate.org/ForumMailingli ... AskForHelp

There is a very good reason that the forum policy tells you to post your mapping files, your code, and any stack trace. That's what it takes to solve problems. Vague descriptions are not enough.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 2:22 pm 
Beginner
Beginner

Joined: Wed Jul 06, 2005 8:18 pm
Posts: 23
You can set this property from your hibernate.cfg.xml as:

<property name="hibernate.cglib.use_reflection_optimizer">true</property>

This will you a more descriptive error message. I've run into this issue mostly from mapping nullable colums to primitive types :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 2:30 pm 
Newbie

Joined: Thu Jul 07, 2005 1:51 pm
Posts: 15
hibernate.cfg.xml:

Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/rampv2</property>
        <property name="hibernate.connection.username">rampv2user</property>
        <property name="hibernate.connection.password">r4mp0R</property>
        <property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
        <property name="show_sql">true</property>
        <property name="transaction.factory_class">
             org.hibernate.transaction.JDBCTransactionFactory
        </property>
        <property name="hibernate.cache.provider_class">
             org.hibernate.cache.HashtableCacheProvider
        </property>
        <property name="hibernate.hbm2ddl.auto">update</property>
      <property name="hibernate.cglib.use_reflection_optimizer">
          false
      </property>

      <mapping resource="net/hatfieldgroup/rampv2/biz/wq/WQAnalyte.hbm.xml"/>
      <mapping resource="net/hatfieldgroup/rampv2/biz/wq/WQSample.hbm.xml"/>
      <mapping resource="net/hatfieldgroup/rampv2/biz/wq/WQSite.hbm.xml"/>
      <mapping resource="net/hatfieldgroup/rampv2/biz/sed/SedAnalyte.hbm.xml"/>
      <mapping resource="net/hatfieldgroup/rampv2/biz/sed/SedSample.hbm.xml"/>
      <mapping resource="net/hatfieldgroup/rampv2/biz/sed/SedSite.hbm.xml"/>
      <mapping resource="net/hatfieldgroup/rampv2/biz/Lease.hbm.xml"/>
      <mapping resource="net/hatfieldgroup/rampv2/biz/Waterbody.hbm.xml"/>
      <mapping resource="net/hatfieldgroup/rampv2/auth/RampUser.hbm.xml"/>
      <mapping resource="net/hatfieldgroup/rampv2/biz/lookup/UserRoles.hbm.xml"/>
    </session-factory>

</hibernate-configuration>


WQAnalyte.hbm.xml:

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>


WQAnalyte.java:

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

import java.util.Collection;

public class WQAnalyte
{
   private Long analyteID;
   private String analyteName;
   private String analyteCategory;
   private String units;
   private String abbreviation;
   private Collection samples;


   public Long getAnalyteID(){
      return analyteID;
   }

   public String getAnalyteName(){
      return analyteName;
   }

   public String getAnalyteCategory(){
      return analyteCategory;
   }

   public String getUnits(){
      return units;
   }

   public String getAbbreviation(){
      return abbreviation;
   }

   public Collection getSamples(){
      return samples;
   }

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

   public void setAnalyteName(String analyteName){
      this.analyteName = analyteName;
   }

   public void setAnalyteCategory(String analyteCategory){
      this.analyteCategory = analyteCategory;
   }

   public void setUnits(String units){
      this.units = units;
   }

   public void setAbbreviation(String abbreviation){
      this.abbreviation = abbreviation;
   }

   public void setSamples(Collection samples){
      this.samples = samples;
   }
};




The stack trace unfortunately is just shown in my command window (I'm using Ant with Junit and don't know how to redirect that output) but the source is WQSample.setAnalyteID.



[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 2:34 pm 
Newbie

Joined: Thu Jul 07, 2005 1:51 pm
Posts: 15
It looks like there's a ClassCastException happening that is causing this. However when I check the contents of the DB that field only contains integer values.

Hibernate should understand how to convert a MySQL bigint(20) into a java.lang.Long, correct?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 2:38 pm 
Newbie

Joined: Thu Jul 07, 2005 8:10 am
Posts: 6
Location: St. Louis, MO
contec wrote:
The stack trace unfortunately is just shown in my command window (I'm using Ant with Junit and don't know how to redirect that output) but the source is WQSample.setAnalyteID.

Try ant -logfile <file> [target]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 2:38 pm 
Newbie

Joined: Thu Jul 07, 2005 1:51 pm
Posts: 15
ctran wrote:
You can set this property from your hibernate.cfg.xml as:

<property name="hibernate.cglib.use_reflection_optimizer">true</property>

This will you a more descriptive error message. I've run into this issue mostly from mapping nullable colums to primitive types :)


Setting this value doesn't change the output I'm getting.

The column in question doesn't contain any null values.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 2:40 pm 
Newbie

Joined: Thu Jul 07, 2005 1:51 pm
Posts: 15
burke_e wrote:
contec wrote:
The stack trace unfortunately is just shown in my command window (I'm using Ant with Junit and don't know how to redirect that output) but the source is WQSample.setAnalyteID.

Try ant -logfile <file> [target]


Perfect, thanks -

Here's the stack trace:

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 3:09 pm 
Newbie

Joined: Thu Jul 07, 2005 1:51 pm
Posts: 15
I've tried changing all the java.lang.Longs to long, that didn't change anything, then I tried changing them all to primitive ints - still getting the same error.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 3:09 pm 
Newbie

Joined: Thu Jul 07, 2005 1:51 pm
Posts: 15
Doesn't really make any sense that I'm still showing a ClassCastException when I'm only using primitives...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 10:46 am 
Newbie

Joined: Tue May 31, 2005 8:48 am
Posts: 11
Location: Blumenau - Santa Catarina - Brasil
Hi

If you used Interceptor interface in your application, you need return null in method instantiate of class what implement Interface Interceptor. I make this in my tests.


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