-->
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.  [ 8 posts ] 
Author Message
 Post subject: I Can't load object ,But can list.get(0) the same object!?
PostPosted: Mon Aug 30, 2004 3:57 am 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
2.1.2

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.vcs.china.poweracl.extension.bean.Trade" table="trade">
<jcs-cache usage="read-write"/>
<id name="trade_id" type="int">
<column name="trade_id" not-null="true"/>
<generator class="native"/>
</id>
<property name="trade_name">
<column name="trade_name" sql-type="varchar(100)"/>
</property>
<property name="trade_desc" type="string">
<column name="trade_desc"/>
</property>
</class>
</hibernate-mapping>


Trade t=(Trade)s.load(Trade.class,new String("4"));
System.out.println("get name: "+t.getTrade_name());


Hibernate: select trade0_.trade_id as trade_id0_, trade0_.trade_name as trade_name0_, trade0_.trade_desc as trade_desc0_ from trade trade0_ where trade0_.trade_id=?
java.lang.ClassCastException
at net.sf.hibernate.type.IntegerType.set(IntegerType.java:31)
at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:48)
at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:35)
at net.sf.hibernate.loader.Loader.bindPositionalParameters(Loader.java:674)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:713)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:185)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:831)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:851)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:57)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:49)
at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:419)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2081)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1955)
at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1884)
at com.vcs.china.poweracl.extension.HiberTest.main(HiberTest.java:44)
Exception in thread "main"


MySQL 3.23.56 :

log4j.category.com.pow2=info, stdout, R


I can't load an object.But I can list them and use the method
Code:
list.get(0);
to get it!!!

I means that if I use the code:

Code:

Trade t=(Trade)s.load(Trade.class,new String("4"));

I will get an ClassCastException.
But if I use the following code :

Code:

List tradeList=s.find("from Trade");
Trade trade=(Trade)list.get(0);

It can work well? Why ?? It is Hibernate's bug?

_________________
You are not alone...


Top
 Profile  
 
 Post subject: mistake
PostPosted: Mon Aug 30, 2004 5:07 am 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
Sorry, its my mistake! the code
Code:
Trade t=(Trade)s.load(Trade.class,new String("4"));


should be
Code:
Trade t=(Trade)s.load(Trade.class,new Integer("4"));


Because the id in database is int!

: )

_________________
You are not alone...


Top
 Profile  
 
 Post subject: Same prob
PostPosted: Wed Sep 22, 2004 5:07 am 
Beginner
Beginner

Joined: Tue Sep 07, 2004 3:58 am
Posts: 23
Same problem here.....

I tried the list thingy.... it works.

Also its nice to know a workaround i

_________________
People keep asking me if i know Tyler Durden....


Top
 Profile  
 
 Post subject: Re: Same prob
PostPosted: Wed Sep 22, 2004 6:41 am 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
Schokoladenhase wrote:
Same problem here.....

I tried the list thingy.... it works.

Also its nice to know a workaround i

_________________
You are not alone...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 6:52 am 
Beginner
Beginner

Joined: Tue Sep 07, 2004 3:58 am
Posts: 23
Hm....
Actually my identifier IS a string, so my load looks like

Konto t = new Konto();
t.setID("someidentifier");
session.save(t);
Konto k = session.load(Konto.class,t.getID);
...

But it should work fine as well ....

Will try to switch to an INT identifier if it helps....

_________________
People keep asking me if i know Tyler Durden....


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 6:56 am 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
The id in your database is a varchar or integer? what database do you use?

_________________
You are not alone...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 7:03 am 
Beginner
Beginner

Joined: Tue Sep 07, 2004 3:58 am
Posts: 23
MySQL 3.2.3

id is a varchar(32), automatically created by hibernate mapping:
<id name="id" type="string">
<column name="ID" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"></generator>
</id>

_________________
People keep asking me if i know Tyler Durden....


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 7:18 am 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
Your full code and full stack trace? Maybe I will answer you some hours later. now have a meeting. :-(

_________________
You are not alone...


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