-->
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.  [ 5 posts ] 
Author Message
 Post subject: UserType breaks WhereParser because it expects a LiteralType
PostPosted: Fri Aug 13, 2004 6:08 am 
Beginner
Beginner

Joined: Wed Sep 24, 2003 11:06 am
Posts: 21
Location: Denmark
Hibernate version: 2.1.6
Full stack trace of any exception that occurs:
ERROR da.HibernateHQLEntityLoader (Client:localhost) - Error while getting identifiction hits
net.sf.hibernate.QueryException: Could not format constant value to SQL literal: com.mds.pepland.persistence.IdentificationHitRating.ELECTED [from com.mds.pepland.persistence.IdentificationHit ih where (ih.manualRating=com.mds.pepland.persistence.IdentificationHitRating.ELECTED or (ih.manualRating=com.mds.pepland.persistence.IdentificationHitRating.UNRATED and ih.machineRating=com.mds.pepland.persistence.IdentificationHitRating.ELECTED)) and ih.identification.spectrum.acquisition.sample.id in (:entityIds0_)]
at net.sf.hibernate.hql.WhereParser.doToken(WhereParser.java:399)
at net.sf.hibernate.hql.WhereParser.token(WhereParser.java:251)
at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:123)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:294)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1562)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1533)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at com.mds.pepland.da.HibernateHQLEntityLoader.loadIdentificationHitsFromLinks(HibernateHQLEntityLoader.java:294)
at com.mds.pepland.da.HibernateHQLEntityLoader.loadProteinMatches(HibernateHQLEntityLoader.java:77)
at com.mdsd.epir.subcontrol.GetGroupsHandler.handleEvent(GetGroupsHandler.java:111)
at com.mds.gw.core.impl.SimpleEventDispatcher.notifyListeners(SimpleEventDispatcher.java:102)
at com.mds.gw.core.impl.ChainingEventDispatcher.dispatch(ChainingEventDispatcher.java:36)
at com.mds.gw.core.impl.SimpleEventDispatcher.dispatchEvent(SimpleEventDispatcher.java:42)
at com.mds.gw.core.impl.SimpleEventBroker.dispatchEvent(SimpleEventBroker.java:101)
at com.mds.gw.http.HttpGatewayImpl.handle(HttpGatewayImpl.java:133)
at com.mds.gw.http.GatewayServlet.doGet(GatewayServlet.java:194)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:974)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:555)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java:114)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:186)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:443)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:593)
Caused by: java.lang.ClassCastException: net.sf.hibernate.type.SerializableType
at net.sf.hibernate.hql.WhereParser.doToken(WhereParser.java:396)
... 41 more

Name and version of the database you are using: MySql 4.x

After switching from PersistentEnum to using a UserType, using an enum value in a query breaks WhereParser because using a UserType causes the type system to generate a CustomType and not a LiteralType.
Query as follows:
"from IdentificationHit ih where ih.manualRating=com.mds.pepland.persistence.IdentificationHitRating.UNRATED"

This query worked fine when IdentificationHitRating was a PersistentEnum Implementation, but now that we're using a UserType, it breaks.. This is not a major issue (I can use integer values directly in my queries for now), but I think it should either be fixed or the manual should be updated so it doesn't state that: "Expressions allowed in the where clause include most of the kind of things you could write in SQL: Java public static final constants eg.Color.TABBY"

Hope this makes sense...

regards....

_________________
Hibernate rocks!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 13, 2004 6:48 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
Try this:
Code:
session.createQuery("from IdentificationHit ih where ih.manualRating=?")
    .setParameter(0, IdentificationHitRating.UNRATED, Hibernate.custom(IdentificationHitRating.class)
    .list();

If it does not work, your UserType is impelemented incorrectly.

_________________
Leonid Shlyapnikov


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 13, 2004 6:52 am 
Beginner
Beginner

Joined: Wed Sep 24, 2003 11:06 am
Posts: 21
Location: Denmark
Using a parameter works nicely, and my UserType is fine.. I'm simply trying to point out the fact, that switching from PersistentEnum to UserType breaks queries that uses the enums as constants in the query string, even though the documentation states that doing that sort of thing (even for classes that don't implement PersistentEnum) is supposed to work (Expressions, section 11.8)...

regards...

_________________
Hibernate rocks!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 13, 2004 6:53 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
And you should now, the following HQL is wrong:
Code:
from IdentificationHit ih where ih.manualRating=com.mds.pepland.persistence.IdentificationHitRating.UNRATED

you cannot work with UserType in that manner, you should substitute values with correspoing Types for each UserType parameter, like in my previous post. Uufff, my English :)

_________________
Leonid Shlyapnikov


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 13, 2004 6:56 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
hooverphonique wrote:
Using a parameter works nicely, and my UserType is fine.. I'm simply trying to point out the fact, that switching from PersistentEnum to UserType breaks queries that uses the enums as constants in the query string, even though the documentation states that doing that sort of thing (even for classes that don't implement PersistentEnum) is supposed to work (Expressions, section 11.8)...

You are right, switch from PesistentEnum to UserType breaks you old HQL queries, but as I remember it is noted somewhere.

_________________
Leonid Shlyapnikov


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