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?