-->
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: exception setting property value with CGLIB
PostPosted: Wed Nov 30, 2005 11:08 am 
Newbie

Joined: Wed Nov 30, 2005 10:54 am
Posts: 13
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: : 3.0.5 and rc3 tested

Mapping documents:

Code:
<hibernate-mapping package="cri.univrennes1.fr.accesdonnees">
   <class name="EtablissementDTO" table="ETABLISSEMENT">
   
      <id name="etablissementId" column="ETABLISSEMENT_ID" type="integer">
         <generator class="increment"/>
      </id>
      <property name="etablissementLibelle" column="ETABLISSEMENT_LIBELLE"
         length="60" not-null="false" type="string" />
         
      <set name="Composantes" cascade="save-update" inverse="true" lazy="true">
         <key column="ETABLISSEMENT_ID" />
         <one-to-many class="ComposanteDTO" />
      </set>         
         
   </class>
</hibernate-mapping>


Code:
<hibernate-mapping package="cri.univrennes1.fr.accesdonnees">
   <class name="ComposanteDTO" table="COMPOSANTE" lazy="false">
   
      <id name="composanteId" column="COMPOSANTE_ID" type="integer">
         <generator class="increment"/>
      </id>
      <property name="composanteLibelle" column="COMPOSANTE_LIBELLE"
         length="60" not-null="false" type="string" />
         
      <many-to-one column="ETABLISSEMENT_ID" name="etablissementId" class="EtablissementDTO" />
      
   </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Code:
         session = HibernateUtil.currentSession();
         tx = session.beginTransaction();

         List etabs = session.createCriteria(EtablissementDTO.class).list();

         for (Iterator iter = etabs.iterator(); iter.hasNext();) {
            EtablissementDTO etab = (EtablissementDTO) iter.next();
            System.out.println("Id " + etab.getEtablissementId() + " Nom "
                  + etab.getEtablissementLibelle());
         }

         tx.commit();

         HibernateUtil.closeSession();

Full stack trace of any exception that occurs:

Quote:
org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of cri.univrennes1.fr.accesdonnees.EtablissementDTO.setComposantes
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:3231)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:126)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
at org.hibernate.loader.Loader.doList(Loader.java:2147)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2026)
at org.hibernate.loader.Loader.list(Loader.java:2021)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1375)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:298)
at cri.univrennes1.fr.hibernate.TestClient.listeEtablissements(TestClient.java:140)
at cri.univrennes1.fr.hibernate.TestClient.main(TestClient.java:24)
Caused by: net.sf.cglib.beans.BulkBeanException: org.hibernate.collection.PersistentSet
at cri.univrennes1.fr.accesdonnees.EtablissementDTO$$BulkBeanByCGLIB$$de7095b8.setPropertyValues(<generated>)
at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:212)
... 14 more
Caused by: java.lang.ClassCastException: org.hibernate.collection.PersistentSet
... 16 more


Name and version of the database you are using: : MySQL 4.1.13-standard-log

Hi, I've been getting this error. has anyone got an idea what is wrong.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 11:16 am 
Senior
Senior

Joined: Mon Aug 22, 2005 5:45 am
Posts: 146
make sure that method

cri.univrennes1.fr.accesdonnees.EtablissementDTO.setComposantes(Set set)

does exist.

_________________
Please don't forget to give credit, if my posting helped to solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 11:20 am 
Newbie

Joined: Wed Nov 30, 2005 10:54 am
Posts: 13
Oops, I forgot the classes :

Code:
package cri.univrennes1.fr.accesdonnees;

import org.hibernate.mapping.Set;

public class EtablissementDTO {

   private Integer etablissementId;
    private String etablissementLibelle;

    private Set composantes;

   public Integer getEtablissementId() {
      return etablissementId;
   }

   public void setEtablissementId(Integer etablissementId) {
      this.etablissementId = etablissementId;
   }

   public String getEtablissementLibelle() {
      return etablissementLibelle;
   }

   public void setEtablissementLibelle(String etablissementLibelle) {
      this.etablissementLibelle = etablissementLibelle;
   }

   public Set getComposantes() {
      return composantes;
   }

   public void setComposantes(Set composantes) {
      this.composantes = composantes;
   }


   
}


Code:
package cri.univrennes1.fr.accesdonnees;

public class ComposanteDTO {

    Integer composanteId;
    String composanteLibelle;

    Integer etablissementId;

   public Integer getComposanteId() {
      return composanteId;
   }

   public void setComposanteId(Integer composanteId) {
      this.composanteId = composanteId;
   }

   public String getComposanteLibelle() {
      return composanteLibelle;
   }

   public void setComposanteLibelle(String composanteLibelle) {
      this.composanteLibelle = composanteLibelle;
   }

   public Integer getEtablissementId() {
      return etablissementId;
   }

   public void setEtablissementId(Integer etablissementId) {
      this.etablissementId = etablissementId;
   }


   
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 11:41 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Use "java.lang.Set" as type :

import org.hibernate.mapping.Set;

public class EtablissementDTO {

private Integer etablissementId;
private String etablissementLibelle;

private Set composantes;


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 11:42 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Sorry, "java.util.Set"


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 11:42 am 
Senior
Senior

Joined: Mon Aug 22, 2005 5:45 am
Posts: 146
I cannot see any error in your code and mappings.

Maybe wrong cglib.jar edition?

How about following the hint and set hibernate.cglib.use_reflection_optimizer=false for more info ?

_________________
Please don't forget to give credit, if my posting helped to solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 11:45 am 
Senior
Senior

Joined: Mon Aug 22, 2005 5:45 am
Posts: 146
ah sure! baliukas is right. wrong import, of course.

_________________
Please don't forget to give credit, if my posting helped to solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 11:45 am 
Newbie

Joined: Wed Nov 30, 2005 10:54 am
Posts: 13
baliukas wrote:
Sorry, "java.util.Set"


Thats brilliant, it works .... thanks very much.

Have a nice day and thanks to everybody who replied to my post.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 12:05 pm 
Newbie

Joined: Wed Nov 30, 2005 10:54 am
Posts: 13
Another problem with the same exception :

Here the java code being executed and the mappings are the same :

Code:
         session = HibernateUtil.currentSession();
         tx = session.beginTransaction();

         List etabs = session.createCriteria(EtablissementDTO.class).list();

         for (Iterator iter = etabs.iterator(); iter.hasNext();) {
            EtablissementDTO etab = (EtablissementDTO) iter.next();
            System.out.println("Id " + etab.getEtablissementId() + " Nom "
                  + etab.getEtablissementLibelle());
                     
            for (Iterator iter2 = etab.getComposantes().iterator(); iter2.hasNext();) {
               ComposanteDTO comp = (ComposanteDTO)iter2.next();
               System.out.println("Id " + comp.getComposanteId() + " Nom "
                     + comp.getComposanteLibelle());
            }
         }

         tx.commit();

         HibernateUtil.closeSession();

Quote:
org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of cri.univrennes1.fr.accesdonnees.ComposanteDTO.setEtablissementId
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:3231)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:126)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1916)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:71)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:520)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1493)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:138)
at cri.univrennes1.fr.hibernate.TestClient.listeEtablissements(TestClient.java:150)
at cri.univrennes1.fr.hibernate.TestClient.main(TestClient.java:25)
Caused by: net.sf.cglib.beans.BulkBeanException: cri.univrennes1.fr.accesdonnees.EtablissementDTO
at cri.univrennes1.fr.accesdonnees.ComposanteDTO$$BulkBeanByCGLIB$$a482df66.setPropertyValues(<generated>)
at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:212)
... 16 more
Caused by: java.lang.ClassCastException: cri.univrennes1.fr.accesdonnees.EtablissementDTO
... 18 more


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 12:11 pm 
Senior
Senior

Joined: Mon Aug 22, 2005 5:45 am
Posts: 146
in your mapping, instead of type="integer"
use
type="java.lang.Integer"

_________________
Please don't forget to give credit, if my posting helped to solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 1:35 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Quote:
public class ComposanteDTO {

Integer composanteId;
String composanteLibelle;

Integer etablissementId;

it must be EtablissementDTO, if you map it as "many-to-one"


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 4:34 am 
Newbie

Joined: Wed Nov 30, 2005 10:54 am
Posts: 13
baliukas wrote:
Quote:
public class ComposanteDTO {

Integer composanteId;
String composanteLibelle;

Integer etablissementId;




it must be EtablissementDTO, if you map it as "many-to-one"


Thanks again, but I still have one more problem to resolve :

Heres the code :

Code:
         session = HibernateUtil.currentSession();
         tx = session.beginTransaction();

         ComposanteDTO composante = (ComposanteDTO) session.get(ComposanteDTO.class, primaryKey);
         System.out.println("Id " + composante.getComposanteId() + " Nom "
               + composante.getComposanteLibelle());
         
         tx.commit();

         HibernateUtil.closeSession();


And the exception (the mappings haven't changed) :

Quote:
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3120)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:232)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:173)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:812)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:782)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
at org.hibernate.type.EntityType.resolve(EntityType.java:303)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
at org.hibernate.loader.Loader.doList(Loader.java:2147)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2026)
at org.hibernate.loader.Loader.list(Loader.java:2021)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1375)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:298)
at cri.univrennes1.fr.accesdonnees.services.ComposanteService.listeComposantes(ComposanteService.java:106)
at cri.univrennes1.fr.hibernate.TestClient.main(TestClient.java:26)


and the classes :

Code:
package cri.univrennes1.fr.accesdonnees;

public class ComposanteDTO {

    Integer composanteId;
    String composanteLibelle;

    EtablissementDTO etablissement;

   public Integer getComposanteId() {
      return composanteId;
   }

   public void setComposanteId(Integer composanteId) {
      this.composanteId = composanteId;
   }

   public String getComposanteLibelle() {
      return composanteLibelle;
   }

   public void setComposanteLibelle(String composanteLibelle) {
      this.composanteLibelle = composanteLibelle;
   }

   public EtablissementDTO getEtablissement() {
      return etablissement;
   }

   public void setEtablissement(EtablissementDTO etablissement) {
      this.etablissement = etablissement;
   }

}


Code:
package cri.univrennes1.fr.accesdonnees;

import java.util.Set;

public class EtablissementDTO {

   private Integer etablissementId;
    private String etablissementLibelle;

    private Set composantes;

   public Integer getEtablissementId() {
      return etablissementId;
   }

   public void setEtablissementId(Integer etablissementId) {
      this.etablissementId = etablissementId;
   }

   public String getEtablissementLibelle() {
      return etablissementLibelle;
   }

   public void setEtablissementLibelle(String etablissementLibelle) {
      this.etablissementLibelle = etablissementLibelle;
   }

   public Set getComposantes() {
      return composantes;
   }

   public void setComposantes(Set composantes) {
      this.composantes = composantes;
   }

}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 4:47 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
ComposanteDTO anjd EtablissementDTO both need to implement java.io.Serializable


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 4:57 am 
Newbie

Joined: Wed Nov 30, 2005 10:54 am
Posts: 13
dennisbyrne wrote:
ComposanteDTO anjd EtablissementDTO both need to implement java.io.Serializable


Thanks, but that didn't work... any other ideas.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 7:02 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
See debug log, it looks like a problem with infrastructure setup.


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.