-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate ERROR: column does not exist
PostPosted: Fri Dec 17, 2010 1:01 pm 
Newbie

Joined: Fri Dec 17, 2010 12:46 pm
Posts: 3
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


Top
 Profile  
 
 Post subject: Re: Hibernate ERROR: column does not exist
PostPosted: Fri Dec 17, 2010 2:01 pm 
Newbie

Joined: Fri Dec 17, 2010 12:46 pm
Posts: 3
Here's a thought, does it matter that in the query that Hibernate is using the columns are listed as table.column
and when I do a "Create SELECT Query" from the table it lists it as table."column"? If so how would I be able to rectify this problem?

Thanks,

Ryan


Top
 Profile  
 
 Post subject: Re: Hibernate ERROR: column does not exist
PostPosted: Fri Dec 17, 2010 2:24 pm 
Newbie

Joined: Fri Dec 17, 2010 12:46 pm
Posts: 3
Hi All,

It does look like it was related to the way Hibernate was trying to reference the columns. Escaping the column names in the xml and the Class file did the trick. Hopefully somebody will find this helpful some day down the line.

Thanks again,

Ryan


Top
 Profile  
 
 Post subject: Re: Hibernate ERROR: column does not exist
PostPosted: Tue May 10, 2011 4:39 pm 
Newbie

Joined: Tue May 10, 2011 4:37 pm
Posts: 1
Hey rrathsam, I'm having a similar problem. What do you mean by 'escape the column names in the xml'?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.