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?