-->
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.  [ 7 posts ] 
Author Message
 Post subject: ClassCastException when finding a Long value
PostPosted: Fri Mar 11, 2005 2:15 am 
Newbie

Joined: Fri Mar 11, 2005 2:03 am
Posts: 4
I'm getting a ClassCastException when I'm trying to select with the "displayId" as part of the criteria. If I only add the "itemName" to the criteria, everything works fine. Any ideas?

Hibernate version:
2.1.8

Mapping documents:
<property
name="displayedId"
type="java.lang.Long"
column="REQ_DISPLAYED_ID"
not-null="true"
unique="true"
length="22"
>
<meta attribute="field-description">
@hibernate.property
column="REQ_DISPLAYED_ID"
unique="true"
length="22"
not-null="true"
</meta>
</property>
<property
name="itemName"
type="java.lang.String"
column="REQ_ITEM_NAME"
not-null="true"
length="50"
>
<meta attribute="field-description">
@hibernate.property
column="REQ_ITEM_NAME"
length="50"
not-null="true"
</meta>
</property>

Code between sessionFactory.openSession() and session.close():
public ArrayList findRequests (RequestDO requestDO) throws HibernateException, InvalidSearchStringException {
Session session;
session = hf.getSession();
MatchMode mode = null;
Criteria crit = session.createCriteria(Request.class);

String displayedId = requestDO.getDisplayedId();
if (displayedId != null && !displayedId.equals("")) {
try {
mode = determineSearchType(displayedId);
} catch (InvalidSearchStringException e) {
throw e;
}
displayedId = cleanSearchString(displayedId, mode);
//crit.add(Expression.sql("REQ_DISPLAYED_ID LIKE '"+displayedId+"'"));// ("displayedId"), displayedId, mode));
crit.add(Expression.ilike("displayedId", displayedId, mode));
}

String itemName = requestDO.getItemName();
if (itemName != null && !itemName.equals("")) {
try {
mode = determineSearchType(itemName);
} catch (InvalidSearchStringException e) {
throw e;
}
itemName = cleanSearchString(itemName, mode);
//crit.add(Expression.sql("REQ_DISPLAYED_ID LIKE '"+itemName+"'"));// ("displayedId"), displayedId, mode));
crit.add(Expression.ilike("itemName", itemName, mode));

}


ArrayList retList = new ArrayList();
try {
retList = (ArrayList) crit.list();
session.close();
} catch (HibernateException e) {
throw e;
}
return retList;

Full stack trace of any exception that occurs:
java.lang.ClassCastException
at net.sf.hibernate.type.LongType.set(LongType.java:35)
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:753)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:793)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:138)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1063)
at net.sf.hibernate.loader.Loader.list(Loader.java:1054)
at net.sf.hibernate.loader.CriteriaLoader.list(CriteriaLoader.java:118)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3660)
at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:238)
at org.adnet.apas.businessobject.impl.RequestBOImpl.findRequests(RequestBOImpl.java:409)
at TestBO.main(TestBO.java:71)


Name and version of the database you are using:
Oracle 9i

The generated SQL (show_sql=true):
Hibernate: select this.REQ_DB_ID_PK as REQ_DB_I1_4_, this.REQ_REQUIREMENT_SOURCE as REQ_REQU2_4_, this.REQ_FUNDED_DATE as REQ_FUND3_4_, this.REQ_SPEND_PLAN_ITEM_NUMBER as REQ_SPEN4_4_, this.REQ_PROJECT_CODE as REQ_PROJ5_4_, this.REQ_ITEM_NAME as REQ_ITEM6_4_, this.REQ_QUANITY as REQ_QUAN7_4_, this.REQ_REQUIRED_DT as REQ_REQU8_4_, this.REQ_TASK_ID as REQ_TASK9_4_, this.REQ_CORE_SITE as REQ_COR10_4_, this.REQ_ITEM_DETAILS as REQ_ITE11_4_, this.REQ_DISPLAYED_ID as REQ_DIS12_4_, this.REQ_STATE_CREATE_DT as REQ_STA13_4_, this.REQ_STATE_ACQUISITION_DT as REQ_STA14_4_, this.REQ_STATE_APPROVED_DT as REQ_STA15_4_, this.REQ_STATE_REJECTED_DT as REQ_STA16_4_, this.REQ_STATE_CLOSED_DT as REQ_STA17_4_, this.REQ_UNIT_PRICE as REQ_UNI18_4_, this.REQ_FUNDED_BY as REQ_FUN19_4_, this.SITE_ID_FK as SITE_ID_FK4_, this.USER_ID_FK as USER_ID_FK4_, this.REQ_STATE_ID_FK as REQ_STA22_4_, this.MODUSER_ID_FK as MODUSER23_4_, site1_.SITE_ID_PK as SITE_ID_PK0_, site1_.SITE_NAME as SITE_NAME0_, userinfo2_.USER_ID_PK as USER_ID_PK1_, userinfo2_.USER_FIRST_NAME as USER_FIR2_1_, userinfo2_.USER_MIDDLE_NAME as USER_MID3_1_, userinfo2_.USER_LAST_NAME as USER_LAS4_1_, userinfo2_.USER_LOGIN as USER_LOGIN1_, userinfo2_.USER_EMAIL as USER_EMAIL1_, requeststa3_.REQ_STATE_ID_PK as REQ_STAT1_2_, requeststa3_.REQ_STATE_NAME as REQ_STAT2_2_, userinfo4_.USER_ID_PK as USER_ID_PK3_, userinfo4_.USER_FIRST_NAME as USER_FIR2_3_, userinfo4_.USER_MIDDLE_NAME as USER_MID3_3_, userinfo4_.USER_LAST_NAME as USER_LAS4_3_, userinfo4_.USER_LOGIN as USER_LOGIN3_, userinfo4_.USER_EMAIL as USER_EMAIL3_ from REQUEST this left outer join SITE site1_ on this.SITE_ID_FK=site1_.SITE_ID_PK left outer join USER_INFO userinfo2_ on this.USER_ID_FK=userinfo2_.USER_ID_PK left outer join REQUEST_STATE requeststa3_ on this.REQ_STATE_ID_FK=requeststa3_.REQ_STATE_ID_PK left outer join USER_INFO userinfo4_ on this.MODUSER_ID_FK=userinfo4_.USER_ID_PK where lower(this.REQ_DISPLAYED_ID) like ? and lower(this.REQ_ITEM_NAME) like ?

Debug level Hibernate log excerpt:
00:45:13,246 DEBUG SessionImpl:560 - opened session
00:45:27,307 DEBUG SessionImpl:2267 - flushing session
00:45:27,307 DEBUG SessionImpl:2467 - Flushing entities and processing referenced collections
00:45:27,307 DEBUG SessionImpl:2808 - Processing unreferenced collections
00:45:27,307 DEBUG SessionImpl:2822 - Scheduling collection removes/(re)creates/updates
00:45:27,307 DEBUG SessionImpl:2291 - Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
00:45:27,307 DEBUG SessionImpl:2296 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
00:45:27,307 DEBUG SessionImpl:1828 - Dont need to execute flush
00:45:27,307 DEBUG BatcherImpl:204 - about to open: 0 open PreparedStatements, 0 open ResultSets
00:45:27,307 DEBUG DriverManagerConnectionProvider:84 - total checked-out connections: 0
00:45:27,307 DEBUG DriverManagerConnectionProvider:90 - using pooled JDBC connection, pool size: 0
00:45:27,307 DEBUG SQL:230 - select this.REQ_DB_ID_PK as REQ_DB_I1_4_, this.REQ_REQUIREMENT_SOURCE as REQ_REQU2_4_, this.REQ_FUNDED_DATE as REQ_FUND3_4_, this.REQ_SPEND_PLAN_ITEM_NUMBER as REQ_SPEN4_4_, this.REQ_PROJECT_CODE as REQ_PROJ5_4_, this.REQ_ITEM_NAME as REQ_ITEM6_4_, this.REQ_QUANITY as REQ_QUAN7_4_, this.REQ_REQUIRED_DT as REQ_REQU8_4_, this.REQ_TASK_ID as REQ_TASK9_4_, this.REQ_CORE_SITE as REQ_COR10_4_, this.REQ_ITEM_DETAILS as REQ_ITE11_4_, this.REQ_DISPLAYED_ID as REQ_DIS12_4_, this.REQ_STATE_CREATE_DT as REQ_STA13_4_, this.REQ_STATE_ACQUISITION_DT as REQ_STA14_4_, this.REQ_STATE_APPROVED_DT as REQ_STA15_4_, this.REQ_STATE_REJECTED_DT as REQ_STA16_4_, this.REQ_STATE_CLOSED_DT as REQ_STA17_4_, this.REQ_UNIT_PRICE as REQ_UNI18_4_, this.REQ_FUNDED_BY as REQ_FUN19_4_, this.SITE_ID_FK as SITE_ID_FK4_, this.USER_ID_FK as USER_ID_FK4_, this.REQ_STATE_ID_FK as REQ_STA22_4_, this.MODUSER_ID_FK as MODUSER23_4_, site1_.SITE_ID_PK as SITE_ID_PK0_, site1_.SITE_NAME as SITE_NAME0_, userinfo2_.USER_ID_PK as USER_ID_PK1_, userinfo2_.USER_FIRST_NAME as USER_FIR2_1_, userinfo2_.USER_MIDDLE_NAME as USER_MID3_1_, userinfo2_.USER_LAST_NAME as USER_LAS4_1_, userinfo2_.USER_LOGIN as USER_LOGIN1_, userinfo2_.USER_EMAIL as USER_EMAIL1_, requeststa3_.REQ_STATE_ID_PK as REQ_STAT1_2_, requeststa3_.REQ_STATE_NAME as REQ_STAT2_2_, userinfo4_.USER_ID_PK as USER_ID_PK3_, userinfo4_.USER_FIRST_NAME as USER_FIR2_3_, userinfo4_.USER_MIDDLE_NAME as USER_MID3_3_, userinfo4_.USER_LAST_NAME as USER_LAS4_3_, userinfo4_.USER_LOGIN as USER_LOGIN3_, userinfo4_.USER_EMAIL as USER_EMAIL3_ from REQUEST this left outer join SITE site1_ on this.SITE_ID_FK=site1_.SITE_ID_PK left outer join USER_INFO userinfo2_ on this.USER_ID_FK=userinfo2_.USER_ID_PK left outer join REQUEST_STATE requeststa3_ on this.REQ_STATE_ID_FK=requeststa3_.REQ_STATE_ID_PK left outer join USER_INFO userinfo4_ on this.MODUSER_ID_FK=userinfo4_.USER_ID_PK where lower(this.REQ_DISPLAYED_ID) like ? and lower(this.REQ_ITEM_NAME) like ?
00:45:27,307 DEBUG BatcherImpl:253 - preparing statement


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 11, 2005 8:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You can't use a "like" on long properties, I'd say


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 11, 2005 9:39 am 
Newbie

Joined: Fri Mar 11, 2005 2:03 am
Posts: 4
I'm beginning to agree, unfortunately :-/


Of course, the following SQL works fine when I use SQLPlus or Toad...

SELECT * FROM REQUEST WHERE req_displayed_id LIKE '11%';

Any other idesa


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 11, 2005 11:09 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Hibernate does not use TOAD to retrieve results ;-)
Why on earth are you doing a like on a numeric value?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 11, 2005 11:24 am 
Newbie

Joined: Fri Mar 11, 2005 2:03 am
Posts: 4
The specific numeric is a field that the user sees that's an DISPLAY ID on an entity; however, it's not the entity's DB ID (all DB IDs are from one sequence which is required for my history architecture, the DISPLAY ID comes from a sequence specific for the entity).

A user may want to search the entity by DISPLAY ID 845*, *432, etc...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 11, 2005 11:56 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Could you not just map it as a string and change your POJO. I suspect the oracle driver may do some converting for you.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 11, 2005 11:57 am 
Newbie

Joined: Fri Mar 11, 2005 2:03 am
Posts: 4
Agreed, already did that so I could move past this issue ;-)


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