-->
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.  [ 5 posts ] 
Author Message
 Post subject: Mapping a list containing an object :PropertyAccessException
PostPosted: Sun Jun 18, 2006 9:57 pm 
Newbie

Joined: Sun Jun 18, 2006 9:41 pm
Posts: 5
Hibernate 3.2.CR2
MySQL 5.0 / InnoDB

A RescueCenter contains 0...* Pet objects. A Pet contains a note:String and data:PetData.

I'm at a lost of how to fix the mapping exception. Any help would be much appreciated!!


-------------- BEANS --------------
public class RescueCenter {
private Integer idRescueCenter;

// ArrayList of Pet objects
private ArrayList pets = new ArrayList();

public ArrayList getPets() {
return pets;
}
public void setPets( ArrayList pets ) {
this.pets = pets;
}
}

public class Pet {
private String note;
private PetData data;

public PetData getData() {
return data;
}
public void setData( PetData data ) {
this.data = data;
}
public String getNote() {
return note;
}
public void setNote( String note ) {
this.note = note;
}
}

public class PetData {
private Integer primaryKey;
private String breed;
...
}


-------------- MAPPING --------------
<class name="RescueCenter" table="rescue_center">
<id name="idRescueCenter">
<generator class="increment" />
</id>
<list name="pets" table="pets" >
<key column="idRescueCenter" />
<index column="position" />
<composite-element class="Pet" >
<property name="note" column="pet_note" />
<many-to-one name="data" class="PetData" column="idPetData" />
</composite-element>
</list>
</class>

<class name="PetData" table="pet_data" >
<id name="primaryKey" column="idPetData" >
<generator class="increment" />
</id>
<property name="breed" />
</class>


-------------- ERROR --------------
org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.test.RescueCenter.setPets
at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:197)
at org.hibernate.tuple.PojoTuplizer.setPropertyValues(PojoTuplizer.java:167)
at org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2879)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:223)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:158)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:429)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:424)
at com._70stylebox.Driver.save(Driver.java:54)
at com._70stylebox.Driver.main(Driver.java:45)
Caused by: net.sf.cglib.beans.BulkBeanException: org.hibernate.collection.PersistentList
at com._70stylebox.RescueCenter$$BulkBeanByCGLIB$$1b6c3227.setPropertyValues(<generated>)
at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:194)
... 14 more
Caused by: java.lang.ClassCastException: org.hibernate.collection.PersistentList
... 16 more


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 18, 2006 11:53 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
When you see that exception, the first thing to do is to follow its advice.
VeryHelpfulExceptionMessage wrote:
org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.test.RescueCenter.setPets

I'm a very helpful person, so I'll (very helpfully, IMHO ;) point out the very helpful part of that message:
set hibernate.cglib.use_reflection_optimizer=false for more info

Actually, I'm not sure how it gets that far, seeing as you've got a <list> without a <list-index>. I didn't know that that was possible. Chances are, the exception is a side effect of the bad mapping.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 19, 2006 2:32 am 
Regular
Regular

Joined: Tue May 16, 2006 3:32 am
Posts: 117
Quote:
public ArrayList getPets() {
return pets;
}
public void setPets( ArrayList pets ) {
this.pets = pets;
}


Always use collection interfaces List, Set, etc in your get/set methods. So modify the above code to

public List getPets() {
return pets;
}
public void setPets( List pets ) {
this.pets = pets;
}


Top
 Profile  
 
 Post subject: Prolly Jaws is right
PostPosted: Mon Jun 19, 2006 3:50 am 
Beginner
Beginner

Joined: Wed Nov 23, 2005 12:55 pm
Posts: 23
If you look at your stack trace you see also this error:

Caused by: java.lang.ClassCastException: org.hibernate.collection.PersistentList

Well prolly hibernate wants to set his PersistenList object in your ArrayList which won't work.
As Jaws said you should best use List or even the Collection interface if sorting isn't required. If possible always use interfaces that goes for everything in java imho.


Top
 Profile  
 
 Post subject: Much thanks!
PostPosted: Mon Jun 19, 2006 9:17 pm 
Newbie

Joined: Sun Jun 18, 2006 9:41 pm
Posts: 5
tenwit: I read the exception, but choose to ignore it ;D I did the same exact mapping at work and no exceptions were thrown so I figured I could replicate it at home with the same results. Of course, I was doing it all from memory, and the table names were different (same structure). I figured I must of messed something up. Thus, the post.

As far as the <index> vice <list-index>, all the examples in 'Hibernate in Action' show <index column... /> (for ex. pg 231).


Jayeshj: As soon as I read your post, I wanted to slap myself. That did the trick. All is well...more questions to follow.


Much thanks to all that responded!


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