• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception setting property value with CGLIB

 
Pranav Pal
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Pranav Pal
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 )
 
Pranav Pal
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 74
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic