-->
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: MySQL variables and named parameters
PostPosted: Wed Nov 10, 2004 12:19 pm 
Newbie

Joined: Wed Nov 10, 2004 11:49 am
Posts: 1
Greetings,

I'm having trouble with a query that uses MySQL variables and assigns the result of a query to the variable. MySQL uses the ":=" operator as a variable assignment operator, and unfortunately it seems like it's being treated as a named query parameter, because of the ":" in the query.

The query looks like this:

Code:
<sql-query name="com.mycompany.core.DentalFamilyMember.customerIds">
        <return alias="dental" class="com.mycompany.core.DentalFamilyMember"/>
            <![CDATA[
            select {dental.*} from Customer customer INNER JOIN DentalFamilyMember dental ON (customer.id=dental.customerId and customer.businessId=dental.businessId and customer.businessId = ? and customer.optedIn=?) where (@a:=(DATE_FORMAT(dental.nextAppointmentDate,'%Y-%m-%d') < ? or dental.nextAppointmentDate is null) and (DATE_FORMAT(dental.lastVisit,'%Y-%m-%d') <= ? and dental.reminderSent=?)) or ( @a = 1 and DATE_FORMAT(dental.reminderSentDate,'%Y-%m-%d') <= ? and
dental.reminderSent=?) order by dental.lastVisit desc;
            ]]>
        </sql-query>


When I run the query, I get a Hibernate JDBCException, caused by a MySQL SQLException:

Code:
Caused by: java.sql.SQLException: No value specified for parameter 8
        at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.jav
a:2201)
        at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.jav
a:2154)
        at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:
1452)
        at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
        at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:795)
        at net.sf.hibernate.loader.Loader.doQuery(Loader.java:189)
        at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections
(Loader.java:133)
        at net.sf.hibernate.loader.Loader.doList(Loader.java:950)
        at net.sf.hibernate.loader.Loader.list(Loader.java:941)
        at net.sf.hibernate.loader.SQLLoader.list(SQLLoader.java:92)
        at net.sf.hibernate.impl.SessionImpl.findBySQL(SessionImpl.java:3764)


Is there a way I could perhaps escape the variable assignment operator in the query so that Hibernate would not treat it as a named parameter? I looked through the sources, and I couldn't find a place where such an escape would be handled.

Thank you!

Hibernate version: 2.1.2

Mapping documents:

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

Full stack trace of any exception that occurs:

Name and version of the database you are using: MySQL 4.0.17

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


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.