-->
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.  [ 12 posts ] 
Author Message
 Post subject: exception setting property value with CGLIB
PostPosted: Wed Sep 28, 2005 3:32 pm 
Beginner
Beginner

Joined: Thu Feb 03, 2005 10:42 pm
Posts: 30
I am using hibernate 3 with spring. I have a domain object with a null int field that is causing the following exception when it is loaded from the database and the value of the property ansiProcessor is null in the database.

nested exception is org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of mbs.test_newmodel.domainobjects.entities.Insurer.setAnsiProcessor
org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of

If you are interested the full stack trace is below. The property I am trying to set is called ansiProcessor. I have gone through this over and over looking for a foolish mistake but I can't find one. It is very odd that only this property causes a problem. Thanks for your help.

Here is my class description.

Code:
   <class name="mbs.test_newmodel.domainobjects.entities.Insurer" table="INSURER" lazy="false">
      <id name="id" column="ID" type="int" unsaved-value="-1">
         <generator class="identity"/>
      </id>
      <property name="name" column="NAME" not-null="true"/>
      <property name="website" column="WEBSITE"/>
      <property name="ansiPayerId" column="ANSI_PAYER_ID"/>
      <property name="groupNumber" column="GROUP_NUMBER"/>
      <property name="ansiProcessor" column="ANSI_PROCESSOR"/>
      <property name="companyId" column="COMPANY_ID" not-null="true"/>
      <many-to-one name="mailAddress" class="mbs.test_newmodel.domainobjects.entities.Address"
      column="MAIL_ADDRESS_ID" cascade="all"  />
      <many-to-one name="workPhone" class="mbs.test_newmodel.domainobjects.entities.Phone"
      column="WORK_PHONE_ID" cascade="all"  />
      <many-to-one name="fax" class="mbs.test_newmodel.domainobjects.entities.Phone"
      column="FAX_ID" cascade="all"  />
      <many-to-one name="otherPhone" class="mbs.test_newmodel.domainobjects.entities.Phone"
      column="OTHER_PHONE_ID" cascade="all"  />
   </class>



I tried the same with the not-null flag set to false and I got the same error. I have other classes that have null int fields that work fine. This class only seems to have a problem with this field, yet the groupNumber property does not cause a problem when it is null.

In my Insurer domain object i have these bean methods:
Code:
    /**
    * @return Returns the ansiProcessor.
    */
   public int getAnsiProcessor()
      {
      return ansiProcessor;
      }

   /**
    * @param ansiProcessor The ansiProcessor to set.
    */
   public void setAnsiProcessor(int ansiProcessor)
      {
      this.ansiProcessor = ansiProcessor;
      }



Also here is the sql statement I used to create the insurer table for hsqldb.

Code:
CREATE CACHED TABLE INSURER(
ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 0)  NOT NULL PRIMARY KEY,
NAME VARCHAR,
WEBSITE VARCHAR,
ANSI_PAYER_ID VARCHAR,
GROUP_NUMBER VARCHAR,
MAIL_ADDRESS_ID INTEGER,
OTHER_PHONE_ID INTEGER,
WORK_PHONE_ID INTEGER,
FAX_ID INTEGER,
COMPANY_ID INTEGER,
ANSI_PROCESSOR INTEGER,
CONSTRAINT FKY_INSURER_MAIL_ADDRESS FOREIGN KEY(MAIL_ADDRESS_ID) REFERENCES ADDRESS(ID),CONSTRAINT FKY_INSURER_OTHER_PHONE_ID FOREIGN KEY(OTHER_PHONE_ID) REFERENCES PHONE(ID),CONSTRAINT FKY_INSURER_WORK_PHONE_ID FOREIGN KEY(WORK_PHONE_ID) REFERENCES PHONE(ID),CONSTRAINT FKY_INSURER_FAX_ID FOREIGN KEY(FAX_ID) REFERENCES PHONE(ID),CONSTRAINT FKY_INSURER_COMPANY FOREIGN KEY(COMPANY_ID) REFERENCES COMPANY(ID),CONSTRAINT FKY_INSURER_ANSIPROCESSOR FOREIGN
KEY(ANSI_PROCESSOR) REFERENCES REFERENCE_PARAMETERS(ID))



Full stack trace:

Code:
org.springframework.orm.hibernate3.HibernateSystemException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of mbs.test_newmodel.domainobjects.entities.Insurer.setAnsiProcessor; nested exception is org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of mbs.test_newmodel.domainobjects.entities.Insurer.setAnsiProcessor
org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of mbs.test_newmodel.domainobjects.entities.Insurer.setAnsiProcessor
   at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:203)
   at org.hibernate.tuple.PojoTuplizer.setPropertyValues(PojoTuplizer.java:173)
   at org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2919)
   at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
   at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:530)
   at org.hibernate.loader.Loader.doQuery(Loader.java:436)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
   at org.hibernate.loader.Loader.loadEntity(Loader.java:1345)
   at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:116)
   at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:101)
   at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2471)
   at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:351)
   at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:332)
   at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:113)
   at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:151)
   at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:79)
   at org.hibernate.impl.SessionImpl.load(SessionImpl.java:603)
   at org.hibernate.impl.SessionImpl.load(SessionImpl.java:596)
   at org.springframework.orm.hibernate3.HibernateTemplate$3.doInHibernate(HibernateTemplate.java:438)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:315)
   at org.springframework.orm.hibernate3.HibernateTemplate.load(HibernateTemplate.java:432)
   at org.springframework.orm.hibernate3.HibernateTemplate.load(HibernateTemplate.java:426)
   at mbs.test_newmodel.dao.implementations.hibernate.enitities.InsurerDao.getInsurer(InsurerDao.java:27)
   at mbs.test_newmodel.service.entities.DefaultEntityMgr.getInsurer(DefaultEntityMgr.java:248)
   at mbs.test_newmodel.service.entities.DefaultEntityMgr.main(DefaultEntityMgr.java:423)
Caused by: net.sf.cglib.beans.BulkBeanException
   at mbs.test_newmodel.domainobjects.entities.Insurer$$BulkBeanByCGLIB$$71aa7cfc.setPropertyValues(<generated>)
   at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:200)
   ... 24 more
Caused by: java.lang.NullPointerException
   ... 26 more


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 28, 2005 4:30 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
If nulls are allowed, it makes more sense to use java.lang.Integer instead of int (what value do you expect Hibernate to set your 'ansiProcessor' member variable to if the column is null?)

_________________
nathan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 28, 2005 4:35 pm 
Beginner
Beginner

Joined: Thu Feb 03, 2005 10:42 pm
Posts: 30
nathanmoon wrote:
If nulls are allowed, it makes more sense to use java.lang.Integer instead of int (what value do you expect Hibernate to set your 'ansiProcessor' member variable to if the column is null?)


Ahhh. I was using -1 to represent a null value. Is there a way to do this.
I try to use primitive types if possible for performance...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 28, 2005 4:39 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
wexwarez wrote:
I try to use primitive types if possible for performance...


This is crazy.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 28, 2005 5:11 pm 
Beginner
Beginner

Joined: Thu Feb 03, 2005 10:42 pm
Posts: 30
gavin wrote:
wexwarez wrote:
I try to use primitive types if possible for performance...


This is crazy.


Please expand on your comment this doesn't help me. As far as I know primitive types are much faster to work with than objects.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 28, 2005 5:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
wexwarez wrote:
gavin wrote:
wexwarez wrote:
I try to use primitive types if possible for performance...


This is crazy.


Please expand on your comment this doesn't help me. As far as I know primitive types are much faster to work with than objects.


No, that is not correct.


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

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
gavin wrote:
wexwarez wrote:
I try to use primitive types if possible for performance...


This is crazy.


Really. Even if one were a little more/less efficient than the other, when you are talking about a database application, the 'performance' of primitive int versus java.lang.Integer is the least of your worries... :)

_________________
nathan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 28, 2005 5:23 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
nathanmoon wrote:
gavin wrote:
wexwarez wrote:
I try to use primitive types if possible for performance...


This is crazy.


Really. Even if one were a little more/less efficient than the other, when you are talking about a database application, the 'performance' of primitive int versus java.lang.Integer is the least of your worries... :)


Yeah, of course, but as a matter of fact, primitives are actually a teensy weensy bit *slower* to access via reflection than wrapper classes are. So this guy is getting the exact opposite result he intended. This is a common problem with premature optimization, and one reason why you should never pre-optimize like this.


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

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
Aso the use of the magic number anti pattern.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 28, 2005 6:40 pm 
Beginner
Beginner

Joined: Thu Feb 03, 2005 10:42 pm
Posts: 30
Alright well thanks for the feedback, i have just always tended to use primitive types.

You guys make it sound like this is absurd. If so I wonder why the hibernate spec even seems to encourage using a primitive type for the id value by having a unsaved-value indicator. Of course an id is suppose to be a not null value. But why even use an int here at all? In all the books, examples I have read everyone uses ints. If as one of you pointed out it even takes a hit in performance why not use an Integer?


Although clearly it is discouraged I am curious as to whether or not this is possible to have null values be represented by a special value on properties other than primary ids?


Top
 Profile  
 
 Post subject: How about a draw?
PostPosted: Thu Oct 20, 2005 10:32 pm 
Beginner
Beginner

Joined: Wed Jun 01, 2005 6:51 pm
Posts: 27
Location: Philippines
I have the exact same exception being thrown when a String object member variable maps to a database column (existing database) that is nullable.

should the mapping file have not-null="true"? for that property?

_________________
Mike "Ollie" Oliver


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 2:52 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
There are no problems with nullable strings, probably it is something else.


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