-->
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.  [ 1 post ] 
Author Message
 Post subject: guessType vs. determineType
PostPosted: Tue Apr 18, 2006 11:45 am 
Beginner
Beginner

Joined: Wed Sep 07, 2005 9:57 am
Posts: 20
Hi,

I map an object with the following id-mapping:

...<id name="id" column="FUNCTION_ID" type="long">...

In Hibernate 3.0.5 when i wanted to retrieve an object by id I could simply do something like this

Code:
...
Query q = session.createQuery("from com.whatever c where c.id = :id");   
q.setParameter("id", value); 
retVal = q.uniqueResult();
...


where value is a String. In Hibernate 3.1.3 I get the following exception because the type is determined to be a LongType. In 3.0.5 it was still determined to be a StringType

Quote:
Exception in thread "main" java.lang.ClassCastException: java.lang.String
at org.hibernate.type.LongType.set(LongType.java:42)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:83)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:65)
at org.hibernate.loader.hql.QueryLoader.bindNamedParameters(QueryLoader.java:491)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1577)
at org.hibernate.loader.Loader.doQuery(Loader.java:661)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:757)
[/i]


From the code of the class AbstractQueryImpl I can see that in 3.0.5 the Query setParameter(String name, Object val) method is calling guessType to get the type but in 3.1.3 another method determineType is called first and only if it can not determin the type guessType is called.

Why has that changed. What is the advantage I get for the trade-off of not being able to hand over Strings into setParameter?

All answers are appreciated.
Thanks,
Ronald


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.