-->
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: Starting Hibernate: Reason for QuerySyntaxException unclear
PostPosted: Wed Sep 17, 2008 5:41 pm 
Newbie

Joined: Wed Sep 17, 2008 5:26 pm
Posts: 17
I'm new to Hibernate and started using it in combination with GWT. Actually it works fine since I already got a simple example to work. Anyway I tried to extend the application and ran into some problems I do not understand.

I get a "QuerySyntaxException: users is not mapped [from users]" in the line
Code:
public User[] getUserData() {
      Session session = getSessionFactory().openSession();
      List<User> users = (List<User>) session.createQuery("from users").list(); <-- Exception is thrown here
      session.close();
      return users.toArray( new User[users.size()] );
   }


My User.java looks like this (setters/getters omitted but they exist ;) )
Code:
package HibernateGWT.client;

import com.google.gwt.user.client.rpc.IsSerializable;

public class User implements IsSerializable {

   public long id;
   public String username;
   public String password;
   
   public User() {}
   
   public User( String username, String password ) {
      this.username = username;
      this.password = password;
   }
...setters and getters come here


My mapping file User.hbm.xml placed in the same package as User.java
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
   <class name="HibernateGWT.client.User" table="users">
      <id name="id" type="long" column="id">
         <generator class="increment"/>
      </id>
      <property name="username" column="name" type="java.lang.String"/>
      <property name="password" column="password" type="java.lang.String"/>
   </class>
</hibernate-mapping>


I'm using MySQL and the table users looks like this
Code:
mysql> describe users;
+----------+------------------+------+-----+---------+----------------+
| Field    | Type             | Null | Key | Default | Extra          |
+----------+------------------+------+-----+---------+----------------+
| id       | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name     | varchar(50)      | YES  |     | NULL    |                |
| password | varchar(50)      | YES  |     | NULL    |                |
+----------+------------------+------+-----+---------+----------------+


I do not see where the error is? Anybody got an idea?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 1:52 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
You should use class names, not table names, in your queries.

Code:
session.createQuery("from User")


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.