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