-->
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.  [ 3 posts ] 
Author Message
 Post subject: Trying to make a join error
PostPosted: Mon Aug 14, 2006 12:41 pm 
Beginner
Beginner

Joined: Wed Aug 09, 2006 12:09 pm
Posts: 20
Location: Belgium
Hello all I am having an on going problem trying to make a relationship which is really one-to-one between two tables. I have read through the hibernate documents and found the many ways to do this in the mapping files, but I cannot get any of them to function all I get in the end is

Full stack trace of any exception that occurs:
Code:
     [java] Hibernate: select actiprojec0_.id as id3_, actiprojec0_.name as name
3_, actiprojec0_.name_lower as name3_3_, actiprojec0_.project_code as project4_3
_ from actitime.project actiprojec0_ order by actiprojec0_.id
     [java]Exception in thread "main" org.hibernate.PropertyAccessException: ex
ception setting property value with CGLIB (set hibernate.cglib.use_reflection_op
timizer=false for more info) setter of be.eurodyn.costDB.model.ActiProject.setCo
ntID
     [java]     at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithO
ptimizer(PojoEntityTuplizer.java:215)
     [java]     at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValues(Pojo
EntityTuplizer.java:185)
     [java]     at org.hibernate.persister.entity.AbstractEntityPersister.setPro
pertyValues(AbstractEntityPersister.java:3232)
     [java]     at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLo
ad.java:126)
     [java]     at org.hibernate.loader.Loader.initializeEntitiesAndCollections(
Loader.java:842)
     [java]     at org.hibernate.loader.Loader.doQuery(Loader.java:717)
     [java]     at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollec
tions(Loader.java:224)
     [java]     at org.hibernate.loader.Loader.doList(Loader.java:2150)
     [java]     at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:
2029)
     [java]     at org.hibernate.loader.Loader.list(Loader.java:2024)
     [java]     at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:36
9)
     [java]     at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslato
rImpl.java:300)
     [java]     at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryP
lan.java:146)
     [java]     at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1093)
     [java]     at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
     [java]     at be.eurodyn.costDB.test.HibernateTest.main(HibernateTest.java:
143)
     [java] Caused by: net.sf.cglib.beans.BulkBeanException: org.hibernate.colle
ction.PersistentSet
     [java]     at be.eurodyn.costDB.model.ActiProject$$BulkBeanByCGLIB$$63d44e4
3.setPropertyValues(<generated>)
     [java]     at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithO
ptimizer(PojoEntityTuplizer.java:212)
     [java]     ... 15 more
     [java] Caused by: java.lang.ClassCastException: org.hibernate.collection.Pe
rsistentSet
     [java]     ... 17 more
     [java] Java Result: 1


This seems to be the main error:
Exception in thread "main" org.hibernate.PropertyAccessException: ex
ception setting property value with CGLIB (set hibernate.cglib.use_reflection_op
timizer=false for more info) setter of be.eurodyn.costDB.model.ActiProject.setCo
ntID


Mapping documents:
This is my mapping for the class creating the relationship:
Code:
<id name="id" column="id">
   <generator class="identity" />
</id>

<property name="name" type="string" />
<property name="name_lower" type="string" />
<property name="project_code" type="string" />

<set name="contID" table="cdb_contract" lazy="false" inverse="true">
   <key column="id"/>
   <one-to-many class="be.eurodyn.costDB.model.Contract"/>
</set>



These are the getters and setters, I have also tried these with Integer and Long as the types as suggested in many forum replies but with no success.
Code:
public int getContID() {
   return contID;
}
public void setContID(int contID) {
   this.contID = contID;
}




Name and version of the database you are using:
MySql 5

Thanks for taking the time to read I hope someone can shed a little light I am at my wits end. Also how do I turn use_reflection_optimizer to false I cannot find any docs on how to do this?

Cheers
Martin


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 15, 2006 1:37 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Your mapping specifies that contID is a set of Contract objects. Your setter/getter expects it to be a single int. Something is wrong there. Is contID an int or a collection of Contracts? Assuming that it's supposed to be a colleciton of contracts, change the java code to this:
Code:
public Set<Contract> getContID() {
   return contID;
}
public void setContID(Set<Contract> contID) {
   this.contID = contID;
}
Obviously you'll have to change the type of the contID member variable. You may also want to change the name of the property to be less confusing.

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


Top
 Profile  
 
 Post subject: yeah wrong object type
PostPosted: Wed Aug 16, 2006 3:52 am 
Beginner
Beginner

Joined: Wed Aug 09, 2006 12:09 pm
Posts: 20
Location: Belgium
Yeah that was it. Thanks Tenwit what I needed to return was a Collection. All sorted and working now.

Thanks very much for your response.

cheers
Martin


tenwit wrote:
Your mapping specifies that contID is a set of Contract objects. Your setter/getter expects it to be a single int. Something is wrong there. Is contID an int or a collection of Contracts? Assuming that it's supposed to be a colleciton of contracts, change the java code to this:
Code:
public Set<Contract> getContID() {
   return contID;
}
public void setContID(Set<Contract> contID) {
   this.contID = contID;
}
Obviously you'll have to change the type of the contID member variable. You may also want to change the name of the property to be less confusing.


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