-->
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: Problem with MySQL Query
PostPosted: Thu Feb 12, 2004 3:03 am 
Newbie

Joined: Thu Feb 12, 2004 2:58 am
Posts: 6
Can I use HQL with MySQL?

I tried this, but hibernate doesn't like it.


Query query = session.createSQLQuery("from volleyball_user");
List list = query.list();




I have to do it this way instead.


Query query = session.createSQLQuery("SELECT {volleyball_user.*} from volleyball_user", "volleyball_user", User.class);
List list = query.list();


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 4:35 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Quote:
Can I use HQL with MySQL?

Yes. I think you mean - can I use Hibernate with MySQL
Quote:
I tried this, but hibernate doesn't like it.

Please be more specific. "Doesn't like it" is not a great description of what I think you are trying to say: The following exception is thrown.....
Quote:
Query query = session.createSQLQuery("from volleyball_user");

Use
Code:
Query query = session.createSQLQuery("from VolleyballUser");

or whatever your class name is. You haven't showed me your mappings so I don't know exactly. Please try to help us help you.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 11:21 am 
Newbie

Joined: Thu Feb 12, 2004 2:58 am
Posts: 6
OK let me try again. I was just trying to follow the example from Hibernate's manual, but I get this error message. I can use this kind of HQL with PostGres without any problem.

Query query = session.createQuery("from volleyball_user");
List list = query.list();



SEVERE: Could not execute query

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 'from' at line 1"

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1876)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1098)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1192)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2051)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1496)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:83)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:794)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:188)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:132)
at net.sf.hibernate.loader.Loader.doList(Loader.java:949)
at net.sf.hibernate.loader.Loader.list(Loader.java:940)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:833)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1475)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)







This is the mapping file.
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="hibernate.User" table="volleyball_user">
<id name="id" column="user_id" type="java.lang.String">
<generator class="uuid.hex" />
</id>
<many-to-one
name="group"
class="hibernate.Group"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="group_id"
/>
<property name="username" column="username" type="java.lang.String" update="true" insert="true"/>
<property name="password" column="password" type="java.lang.String" update="true" insert="true"/>
<property name="firstname" column="firstname" type="java.lang.String" update="true" insert="true"/>
<property name="middlename" column="middlename" type="java.lang.String" update="true" insert="true"/>
<property name="lastname" column="lastname" type="java.lang.String" update="true" insert="true"/>
<property name="address1" column="address1" type="java.lang.String" update="true" insert="true"/>
<property name="address2" column="address2" type="java.lang.String" update="true" insert="true"/>
<property name="city" column="city" type="java.lang.String" update="true" insert="true"/>
<property name="state" column="state" type="java.lang.String" update="true" insert="true"/>
<property name="zipcode" column="zipcode" type="java.lang.String" update="true" insert="true"/>
<property name="email" column="email" type="java.lang.String" update="true" insert="true"/>
</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 11:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
With HQL you don't query against table names. use "from hibernate.User"


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 1:18 pm 
Newbie

Joined: Thu Feb 12, 2004 2:58 am
Posts: 6
All right, it works now. Thanks for your help.


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.