File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Exception setting property value with CGLIB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Exception setting property value with CGLIB" Watch "Exception setting property value with CGLIB" New topic
Author

Exception setting property value with CGLIB

Pranav Pal
Ranch Hand

Joined: Nov 04, 2007
Posts: 74
I have an User table in my MySQL database. I changed one column of that table from STATUS(varchar) to ISACTIVE(boolean).

Now when I call any getter method of the User bean, which corresponds to the User table, I get following exception:

exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.bean.Expert.setIsActive

What can be the reason for this?

I have appropriately chaned the user.hbm.xml file and User.java bean class

Thanks in advance


Hakuna Matata!
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Please post your mapping and bean code, using the CODE button below, so that the code keeps its indentations.

I am sure it is probably one simple change.

so if your field is called isactive, and if you called your attribute isActive, then wouldn't that then make your method isIsActive?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Pranav Pal
Ranch Hand

Joined: Nov 04, 2007
Posts: 74
I have changed attribute name to "active" and getter/setter methods are now isActive() and setActive()

Still I am geting exception:
org.hibernate.PropertyAccessException:exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.bean.User.setActive

Code for user.hbm.xml


Code for User.java (Bean)

Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9338
    
110

Originally posted by Pranav Pal:
I changed one column of that table from STATUS(varchar) to ISACTIVE(boolean).



I don't know, how you have changed the column definition. But have you also ensured that when you changed the column from varchar to boolean, you even cleared off this column contents (might be dumb question, if the database already takes care of clearing the contents of the column when you change its schema definition )


[My Blog] [JavaRanch Journal]
Pranav Pal
Ranch Hand

Joined: Nov 04, 2007
Posts: 74
Originally posted by Jaikiran Pai:


I don't know, how you have changed the column definition. But have you also ensured that when you changed the column from varchar to boolean, you even cleared off this column contents (might be dumb question, if the database already takes care of clearing the contents of the column when you change its schema definition )


I didn't need to change the contents as the values for STATUS was NULL in all the tuples.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Please also post your hibernate.cfg.xml file

I see you also have another boolean field



Totally un-related, but why were the database field names have the "is" in front of the name, why not just PAID_USER?

Mark
Pranav Pal
Ranch Hand

Joined: Nov 04, 2007
Posts: 74
I have found that the reason why I was getting exception was that I had mapped a primitive property (active - boolean) to a nullable column (ISACTIVE). Since primitives cannot be null, one cannot map it to a nullable ccolumn. I was not getting the same excpetion for isPaidUser because the type declared for isPaidUser was Boolean (Wrapper class) and not boolean (primitive).

Thank you Mark and Jaikiran for your help
Prashant Langade
Ranch Hand

Joined: Jul 01, 2009
Posts: 71
Hi

I am also facing the same issue.

Here is the code snippet

The main java class.



The ProductFamily pojo mapped to PRODUCT_FAMILY table




The ProductAlive pojo mapped to PRODUCTS_ALIVE table

PRODUCT_FAMILY has one to many relationship with PRODUCTS_ALIVE table



PROUDCTS_ALIVE has three primary keys(Composite primary keys).
The corresponding separate pojo ProductAliveKey representing it.



HBM files

ProductFamily.hbm.xml



ProductAlive.hbm.xml



The database structure




I am getting following exception when i try to run main class.

org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.deere.domain.ProductFamily.setProductAliveList
at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:215)
at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:185)
at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3232)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:253)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:167)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:114)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:559)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:547)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:543)
at com.deere.hibernate.ProductMaintain.main(ProductMaintain.java:46)
Caused by: net.sf.cglib.beans.BulkBeanException: org.hibernate.collection.PersistentBag incompatible with java.util.ArrayList
at com.deere.domain.ProductFamily$$BulkBeanByCGLIB$$29c24265.setPropertyValues(<generated>)
at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:212)
... 14 more
Caused by: java.lang.ClassCastException: org.hibernate.collection.PersistentBag incompatible with java.util.ArrayList
... 16 more
Barclay Dunn
Greenhorn

Joined: Nov 16, 2011
Posts: 3
Pranav Pal wrote:I have found that the reason why I was getting exception was that I had mapped a primitive property (active - boolean) to a nullable column (ISACTIVE). Since primitives cannot be null, one cannot map it to a nullable ccolumn. I was not getting the same excpetion for isPaidUser because the type declared for isPaidUser was Boolean (Wrapper class) and not boolean (primitive).


This is why living in the future is so great: I can benefit from your having had this problem and posting about its solution. As a result I spent 20 minutes on a fix rather than hours trying to figure it out. Thank you!
Ragupathirajan Venkatesan
Ranch Hand

Joined: Aug 18, 2010
Posts: 62
Hi

What changes that you have done to fix this issue as suggested by Pranav Pal in previous reply that he has fixed by making that as wrapper.

Thanks
sankalp suryawanshi
Greenhorn

Joined: Feb 03, 2008
Posts: 4
Pranav Pal wrote:I have found that the reason why I was getting exception was that I had mapped a primitive property (active - boolean) to a nullable column (ISACTIVE). Since primitives cannot be null, one cannot map it to a nullable ccolumn. I was not getting the same excpetion for isPaidUser because the type declared for isPaidUser was Boolean (Wrapper class) and not boolean (primitive).

Thank you Mark and Jaikiran for your help


Me found the same error and fixed using method mentioned by Pranav , Just changed int to Integer and its all fixed. Thanks Pranav
Barclay Dunn
Greenhorn

Joined: Nov 16, 2011
Posts: 3
Ragupathirajan Venkatesan wrote:Hi

What changes that you have done to fix this issue as suggested by Pranav Pal in previous reply that he has fixed by making that as wrapper.

Thanks


I changed this:



to this:


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception setting property value with CGLIB
 
Similar Threads
Hibernate: How to map int type if column is Null able
PropertyAccessException using spring and hibernate, any clues?
Strange Hibernate exception with CGLIB
Hibernate Error - "exception setting property value with CGLIB"
JPA-hibernate-spring config