-->
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.  [ 3 posts ] 
Author Message
 Post subject: Criteria with setMaxResults & setLockMode wrong SQL stmt
PostPosted: Wed May 04, 2005 6:53 am 
Newbie

Joined: Wed May 04, 2005 5:49 am
Posts: 2
Hibernate version: 2.1.8

Mapping documents:

Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping
>
    <class
        name="at.siemens.sx.core.service.fileexchange.FXOrderDAO"
        table="SXFXORDER"
        polymorphism="explicit"
        dynamic-update="true"
        dynamic-insert="false"
        select-before-update="false"
        optimistic-lock="version"
    >
        <cache usage="read-write" />

        <id
            name="id"
            column="id"
            type="java.lang.Integer"
        >
            <generator class="native">
                <param name="sequence">fxorderid_seq</param>
              <!-- 
                  To add non XDoclet generator parameters, create a file named
                  hibernate-generator-params-FXOrderDAO.xml
                  containing the additional parameters and place it in your merge dir.
              -->
            </generator>
        </id>

        <property
            name="orderName"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="orderName"
            length="30"
            not-null="true"
        />

        <property
            name="state"
            type="int"
            update="true"
            insert="true"
            access="property"
            column="state"
            not-null="true"
        />

        <property
            name="attempt"
            type="int"
            update="true"
            insert="true"
            access="property"
            column="attempt"
            not-null="true"
        />

        <property
            name="fileName"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="fileName"
            length="255"
            not-null="true"
        />

        <property
            name="fileDate"
            type="java.util.Date"
            update="true"
            insert="true"
            access="property"
            column="fileDate"
            not-null="true"
        />

        <property
            name="fileSize"
            type="long"
            update="true"
            insert="true"
            access="property"
            column="fileSize"
            not-null="true"
        />

        <property
            name="watchDog"
            type="java.util.Date"
            update="true"
            insert="true"
            access="property"
            column="watchDog"
            not-null="true"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-FXOrderDAO.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Code:
            List dbOrders = session.createCriteria(FXOrderDAO.class)
              .add( Expression.eq("orderName", order.getOrderName()) )
              .add( Expression.le("watchDog", new Date()) )
              .addOrder( Order.asc("fileDate"))
              .setMaxResults(noOfFreeWorkers)
              .setLockMode(LockMode.UPGRADE)
              .list();


Full stack trace of any exception that occurs:

Code:
net.sf.hibernate.exception.SQLGrammarException: Unable to perform find
   at net.sf.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:69)
   at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
   at net.sf.hibernate.impl.SessionImpl.convert(SessionImpl.java:4131)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3663)
   at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:238)
   at at.siemens.sx.core.service.fileexchange.FXTransferController.run(FXTransferController.java:91)
Caused by: java.sql.SQLException: Syntax error or access violation message from server: "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 'limit 5' at line 1"
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)
   at com.mysql.jdbc.Connection.execSQL(Connection.java:2247)
   at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1586)
   at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:296)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at at.siemens.sx.core.service.performance.DataSourceDelegator$DataSourceInvokationHandler.invoke(DataSourceDelegator.java:134)
   at $Proxy57.executeQuery(Unknown Source)
   at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:89)
   at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:880)
   at net.sf.hibernate.loader.Loader.doQuery(Loader.java:273)
   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)
   ... 2 more

Name and version of the database you are using: mysql-4.1.5-gamma-win

The generated SQL (show_sql=true):

Code:
select this.id as id0_, this.orderName as orderName0_, this.state as state0_, this.attempt as attempt0_, this.fileName as fileName0_, this.fileDate as fileDate0_, this.fileSize as fileSize0_, this.watchDog as watchDog0_ from SXFXORDER this where this.orderName=? and this.watchDog<=? order by this.fileDate asc for update limit ?



after the following changes the SQL statement works correct.

... order by this.fileDate asc limit ? for update

Thank you for your assistance
br
Ramses


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 12:59 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Check the forum, I think this mysql bug has been discussed already

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2005 5:16 am 
Newbie

Joined: Wed May 04, 2005 5:49 am
Posts: 2
Hi

I have found an entry, but not in coherence with mySQL.

http://forum.hibernate.org/viewtopic.php?t=929184

What does this mean

Quote:
... has already been fixed, but only in the 2.2 branch ...


I have nothing found in the release notes or download aerea for version 2.2

BR


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