aspose file tools*
The moose likes Object Relational Mapping and the fly likes Could not read the data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Could not read the data" Watch "Could not read the data" New topic
Author

Could not read the data

Gundeti Reddy
Greenhorn

Joined: Jun 28, 2008
Posts: 6
HI All,
I am getting below ClassCastException only for particular data.It is working fine with other data.I could not able to understand whats wrong with my mapping files.If anyone cameacrross these types of problems please help me.I am using Hibernate 2.1.1

1.The Mapping for that coloumn in my hbm file is like below
<property
name="assetNum"
type="long"
column="ASSET_NUM"
not-null="true"
length="15"
/>

2. The Exception that i am getting is,
java.lang.ClassCastException: java.lang.Long incompatible with java.lang.Short
at net.sf.hibernate.type.ShortType.set(ShortType.java:30)
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:673)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:712)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:184)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:132)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:830)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:850)
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:420)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2044)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1918)
at net.sf.hibernate.impl.SessionImpl.internalLoadOneToOne(SessionImpl.java:1872)
at net.sf.hibernate.type.OneToOneType.resolveIdentifier



Thnaks,
Gundeti.
Carl Sayres
Greenhorn

Joined: Sep 24, 2008
Posts: 4
We'd need to see your Java object to be sure, but most likely you declared assetNum as a Short (or short). Change it to a Long (or change your xml mapping to a short). The xml mapping needs to be consistent with the actual data type.

Carl
Gundeti Reddy
Greenhorn

Joined: Jun 28, 2008
Posts: 6
asset_num filed is delcared as required. But i am getting this exception only for particula data.
Please see the below code which says how i am using,


[ Edited to use code tags - Paul Sturrock ]
[ September 25, 2008: Message edited by: Paul Sturrock ]
Carl Sayres
Greenhorn

Joined: Sep 24, 2008
Posts: 4
Perhaps you are getting the exception only when the value is too wide to fit in a short.

Post your POJO (java class) and complete XML mapping.

Carl
Gundeti Reddy
Greenhorn

Joined: Jun 28, 2008
Posts: 6
We are passing only long values to assetNum filed but somehow hibernate is converting it into short type.Thats why i am getting this exception. This problem occuring only for few valuses.For example if pass the value 10000970 for assetNum field, the hibernate is trying to convert it to short type.

1.For your reference the POJO class is


2. The hbm file is,


[ Edited to use code tags - Paul Sturrock ]
[ September 25, 2008: Message edited by: Paul Sturrock ]
Gundeti Reddy
Greenhorn

Joined: Jun 28, 2008
Posts: 6
Its urgent.any help on this.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Could not read the data