-->
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.  [ 2 posts ] 
Author Message
 Post subject: HQL being sent to MySQL server?
PostPosted: Wed Feb 14, 2007 5:06 pm 
Beginner
Beginner

Joined: Sun Feb 20, 2005 12:14 am
Posts: 49
Am trying to execute this code:


Code:
....
....
String queryString = "FROM ImageProcessRequest WHERE entityType = :entityType AND entityId = :entityId";
Session session = this.vandelayConfiguration.getDbContextConfig().getDbContext().currentSession();
Query query = session.createQuery( queryString );
query = query.setString("entityType", obj.getClass().getSimpleName() );
query = query.setString( "entityId", obj.getId().toString() );
....
....


Hibernate version: 3.2

Stack Trace:

I get the follwing error:
Code:
12642 DEBUG org.hibernate.hql.ast.QueryTranslatorImpl [216] - HQL: FROM com.allegrocentral.vandelay.beans.ImageProcessRequest WHERE entityType = :entityType AND entityId = :entityId
12642 DEBUG org.hibernate.hql.ast.QueryTranslatorImpl [217] - SQL: select imageproce0_.id as id20_, imageproce0_.version as version20_, imageproce0_.entityId as entityId20_, imageproce0_.entityType as entityType20_, imageproce0_.priority as priority20_, imageproce0_.requestTimestamp as requestT6_20_ from imageprocessrequest imageproce0_ where imageproce0_.entityType=? and imageproce0_.entityId=?
12642 DEBUG org.hibernate.hql.ast.ErrorCounter [68] - throwQueryException() : no errors
12642 DEBUG org.hibernate.engine.query.HQLQueryPlan [269] - HQL param location recognition took 0 mills (FROM ImageProcessRequest WHERE entityType = :entityType AND entityId = :entityId)
12695 DEBUG com.allegrocentral.vandelay.persistence.daos.base.HibernateDbDao [640] - Query - FROM ImageProcessRequest WHERE entityType = :entityType AND entityId = :entityId was not executed.
java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM ImageProcessRequest WHERE entityType = :entityType AND entityId = :entityId' at line 1
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2975)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1600)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1695)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2998)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2927)
        at com.mysql.jdbc.Statement.execute(Statement.java:535)
        at com.mchange.v2.c3p0.impl.NewProxyStatement.execute(NewProxyStatement.java:899)
        at com.allegrocentral.vandelay.persistence.daos.base.HibernateDbDao.execute(HibernateDbDao.java:629)
        at com.allegrocentral.vandelay.persistence.daos.base.HibernateDbDao.execute(HibernateDbDao.java:621)
        at com.allegrocentral.vandelay.managers.ImageProcessingManager.findImageProcessRequestsForEntity(ImageProcessingManager.java:66)
        at com.allegrocentral.vandelay.daemons.product.images.ImageProcessingDaemon.processRequest(ImageProcessingDaemon.java:114)
        at com.allegrocentral.vandelay.daemons.product.images.ImageProcessingDaemon.runIteration(ImageProcessingDaemon.java:89)
        at com.allegrocentral.vandelay.daemons.AbstractVandelayDaemon.run(AbstractVandelayDaemon.java:53)
12721 DEBUG org.hibernate.engine.query.QueryPlanCache [76] - located HQL query plan in cache (FROM ImageProcessRequest WHERE entityType = :entityType AND entityId = :entityId)
12721 DEBUG org.hibernate.event.def.AbstractFlushingEventListener [58] - flushing session


Seems like Hibernate is parsing the HQL to proper SQL. If I copy and execute that sql via mysql client against the same mysql server, it works fine. Seems like hibernate is trying to send the HQL to the mysql server instead of the SQL query it created after parsing the HQL query.

Any ideas?[/code]


Top
 Profile  
 
 Post subject: Wierd ..
PostPosted: Wed Feb 14, 2007 6:18 pm 
Beginner
Beginner

Joined: Sun Feb 20, 2005 12:14 am
Posts: 49
I put the HQL query in an xml file like such:

Code:
   <query name="imageprocessrequest.by.entityIdAndType">
      FROM ImageProcessRequest WHERE entityType = :entityType AND entityId = :entityId
   </query>


And changed the java code to use this query from the xml file like:

Code:
   Map <String, Object> map = new HashMap<String, Object>();
    map.put("entityType", obj.getClass().getSimpleName());
    map.put("entityId", obj.getId().toString());
    requests = dbdao.findByNamedQuery("imageprocessrequest.by.entityIdAndType", map);


where findByNamedQuery is:

Code:
public List<T> findByNamedQuery(String p_namedQuery, Map<String, Object> p_values)
  {
    Session session = this.getSession();
    Query query = setQueryParams(session.getNamedQuery(p_namedQuery), p_values);

    return findResults(query);
  }


When I do the above my query works fine! I am still at a loss as to why this same query did not work before? Any Ideas?


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