-->
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.  [ 2 posts ] 
Author Message
 Post subject: composite-id and java.lang.ClassCastException
PostPosted: Fri Jul 29, 2005 11:44 am 
Newbie

Joined: Tue Jul 26, 2005 7:10 am
Posts: 5
Hibernate version:
Hibernate 3 Current CVS

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class
name="wdb.Zeiteinheit"
table="ZEITEINHEIT">

<composite-id
name="key"
class="tools.BigDecimalId">
<key-property
name="oid"
type="big_decimal"
column="zeiteinheitid"/>
<key-property
name="classtype"
type="string"
length="32"
column="class_type"/>
</composite-id>
</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Object temp = session.get(Zeiteinheit.class, new BigDecimal(1));
ze = (Zeiteinheit)temp;

Full stack trace of any exception that occurs:
org.hibernate.PropertyAccessException: exception getting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) getter of tools.BigDecimalId.?
at org.hibernate.tuple.PojoComponentTuplizer.getPropertyValues(PojoComponentTuplizer.java:79)
at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:307)
at org.hibernate.type.ComponentType.getHashCode(ComponentType.java:158)
at org.hibernate.engine.EntityKey.getHashCode(EntityKey.java:68)
at org.hibernate.engine.EntityKey.<init>(EntityKey.java:41)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:72)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:634)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:627)
at wdb.Test.testKurs(Test.java:59)
at wdb.Test.main(Test.java:32)
Caused by: java.lang.ClassCastException
at tools.BigDecimalId$$BulkBeanByCGLIB$$a916dd38.getPropertyValues(<generated>)
at net.sf.cglib.beans.BulkBean.getPropertyValues(BulkBean.java:48)
at org.hibernate.tuple.PojoComponentTuplizer.getPropertyValues(PojoComponentTuplizer.java:76)
... 9 more
Exception in thread "main"

and with hibernate.cglib.use_reflection_optimizer false

ERROR - IllegalArgumentException in class: tools.BigDecimalId, getter method of property: oid
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of tools.BigDecimalId.oid
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
at org.hibernate.tuple.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:121)
at org.hibernate.tuple.AbstractComponentTuplizer.getPropertyValues(AbstractComponentTuplizer.java:133)
at org.hibernate.tuple.PojoComponentTuplizer.getPropertyValues(PojoComponentTuplizer.java:88)
at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:307)
at org.hibernate.type.ComponentType.getHashCode(ComponentType.java:158)
at org.hibernate.engine.EntityKey.getHashCode(EntityKey.java:68)
at org.hibernate.engine.EntityKey.<init>(EntityKey.java:41)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:72)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:634)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:627)
at wdb.Test.testKurs(Test.java:59)
at wdb.Test.main(Test.java:32)
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
... 12 more
Exception in thread "main"

Name and version of the database you are using:
Oracle 7.3.3.0.0

The generated SQL (show_sql=true):
nothing

tools.BigDecimalId:
package tools;

import java.math.BigDecimal;

public class BigDecimalId implements java.io.Serializable {
protected String classtype;
protected BigDecimal oid;

public BigDecimalId() {
super();
oid = new BigDecimal(0);
classtype = "";
}

public BigDecimalId(BigDecimal id, String classtype) {
super();
setOid(id);
setClasstype(classtype);
}

public BigDecimal getOid() {
return oid;
}

public void setOid(BigDecimal c_id) {
this.oid = c_id;
}

public String getClasstype() {
return classtype;
}

public void setClasstype(String classtype) {
this.classtype = classtype;
}

public int hashCode() {
return getOid().hashCode() + getClasstype().hashCode();
}
public boolean equals(Object other) {
if (other instanceof BigDecimalId) {
BigDecimalId that = (BigDecimalId) other;
return that.getOid().equals(getOid()) &&
that.getClasstype().equals(getClasstype());
}
else {
return false;
}
}
}

Any hints?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 12:06 pm 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
Maybe I'm not following what you're trying to do here, but shouldn't your code look more like this:

Code:
BigDecimalId bigDecimalId = new BigDecimalId(new BigDecimal(1), "sometype");
Object temp = session.get(Zeiteinheit.class, bigDecimalId);
ze = (Zeiteinheit)temp;


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