Hi All,
I'm fairly new to Hibernate but have been plugging away through the setup and seem to have come to an road block. Whatever I change it keeps coming up with this error stating that the 'id' column cannot be found ( org.postgresql.util.PSQLException: ERROR: column user0_.id does not exist) . My setup is this: I have a simple setup of one class, one table and I'm trying to retrieve all the records in said table.
the class definition is as follows:Code:
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Transient;
import javax.persistence.Version;
import com.google.gwt.user.client.rpc.IsSerializable;
@Entity
public class User implements IsSerializable{
@Id
private Long id;
@Version
private Long version;
private String userName;
private String password;
private Boolean isAuthorized;
public User(){
userName = null;
password = null;
isAuthorized = null;
}
public User(String uName, String pWord){
userName = uName;
password = pWord;
}
public User(UserDTO userDTO){
this.userName = userDTO.getUserName();
this.password = userDTO.getPassword();
this.isAuthorized = false;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserName() {
return userName;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
@Transient
public void setIsAuthorized(Boolean isAuthorized) {
this.isAuthorized = isAuthorized;
}
@Transient
public Boolean getIsAuthorized() {
return isAuthorized;
}
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public void setVersion(Long version) {
this.version = version;
}
public Long getVersion() {
return version;
}
}
The .hbm.xml for the User class is as as follows:Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.tutorial.domain">
<class name="User" table="users">
<id name="id" column="id">
<generator class="SequenceStyleGenerator"/>
</id>
<property name="userName"/>
<property name="password"/>
<property name="isAuthorized"/>
<property name="version"/>
</class>
</hibernate-mapping>
Here is my Hibernate.cfg.xml:Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://localhost/users</property>
<property name="connection.username">test</property>
<property name="connection.password">test</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Path to User.hbm.xml -->
<mapping class="com.test2.shared.User"/>
</session-factory>
</hibernate-configuration>
And here is how I'm trying to use it: Code:
User result = new User(userName, password);
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.getTransaction().begin();
Query getUser = session.createQuery("from User");
Here is the table that was created in the Postreges DB:Code:
CREATE TABLE users
(
id bigint NOT NULL,
passsword character varying(255) NOT NULL,
username character varying(255) NOT NULL,
"version" integer,
CONSTRAINT users_pkey PRIMARY KEY (id)
)
Here is the SQL Query as reported in the debugging information:Code:
select user0_.id as id0_, user0_.isAuthorized as isAuthor2_0_, user0_.password as password0_, user0_.userName as userName0_, user0_.version as version0_ from User user0_
Most of the setup information is right from the beginning tutorial and slightly modified given a few problems I ran into along the way. If it matters this is a GWT Web App with a Postgresql DB. If there's any other information I can get people please let me know.
Thanks muchly in advance,
Ryan