Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Invalid Column Name errir
PostPosted: Tue Jul 10, 2012 4:19 pm 
Newbie

Joined: Tue Jul 10, 2012 4:00 pm
Posts: 2
I am getting an "invalid column name" error when attempting to query a table. Here are the relevant snippets of code. The database is Sybase.

The configuration file:

Code:
<hibernate-configuration>

    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">com.sybase.jdbc4.jdbc.SybDriver</property>
        <property name="connection.url">***</property>
        <property name="connection.username">***</property>
        <property name="connection.password">***</property>
       
        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Names the annotated entity class -->
        <mapping class="javaapplication2.Contact"/>

    </session-factory>

</hibernate-configuration>


The Contact database table:

Code:
ContactID
ContactName
FirstName
LastName
Phone
Ext
Fax
Email
Status
PassCode
CompanyID
LoginName


The Java Bean for the Contact table

Code:
package javaapplication2;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;

@Entity
public class Contact implements Serializable
{
   private int contactID;
   private String contactName;
   private String firstName;
   private String lastName;
   private String phone;
   private String ext;
   private String fax;
   private String email;
   private String status;
   private String passCode;
   private int companyID;
   private String loginName;

   public Contact()
   {
   }

   @Id
   @GeneratedValue(generator = "increment")
   @GenericGenerator(name = "increment", strategy = "increment")
   public int getContactID()
   {
      return contactID;
   }

   public void setContactID(int ContactID)
   {
      this.contactID = ContactID;
   }

   public String getContactName()
   {
      return contactName;
   }

   public void setContactName(String contactName)
   {
      this.contactName = contactName;
   }

   public String getFirstName()
   {
      return firstName;
   }

   public void setFirstName(String firstName)
   {
      this.firstName = firstName;
   }

   public String getLastName()
   {
      return lastName;
   }

   public void setLastName(String lastName)
   {
      this.lastName = lastName;
   }

   public String getPhone()
   {
      return phone;
   }

   public void setPhone(String phone)
   {
      this.phone = phone;
   }

   public String getExt()
   {
      return ext;
   }

   public void setExt(String ext)
   {
      this.ext = ext;
   }

   public String getFax()
   {
      return fax;
   }

   public void setFax(String fax)
   {
      this.fax = fax;
   }

   public String getEmail()
   {
      return email;
   }

   public void setEmail(String email)
   {
      this.email = email;
   }

   public String getStatus()
   {
      return status;
   }

   public void setStatus(String status)
   {
      this.status = status;
   }

   public String getPassCode()
   {
      return passCode;
   }

   public void setPassCode(String passCode)
   {
      this.passCode = passCode;
   }

   public int getCompanyID()
   {
      return companyID;
   }

   public void setCompanyID(int companyID)
   {
      this.companyID = companyID;
   }

   public String getLoginName()
   {
      return loginName;
   }

   public void setLoginName(String loginName)
   {
      this.loginName = loginName;
   }
}


The code that queries the database:

Code:
   SessionFactory sessionFactory = null;
   Configuration configuration = new Configuration();
   configuration.configure();
   ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
   sessionFactory = configuration.buildSessionFactory(serviceRegistry);

   Session session = sessionFactory.openSession();
   session.beginTransaction();
   Query query = session.createQuery("from Contact");
   List result = query.list();
   String temp;
   for (Contact contact : (List<Contact>) result)
   {
       temp = String.format("%s %s, %s/%s", contact.getFirstName(), contact.getLastName(), contact.getEmail(), contact.getPassCode());
       System.out.println(temp);
   }
   session.getTransaction().commit();
   session.close();

   sessionFactory.close();



The query.list() function throws an exception. Here's the log output:

Code:
Jul 10, 2012 2:51:32 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Jul 10, 2012 2:51:32 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.4.Final}
Jul 10, 2012 2:51:32 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jul 10, 2012 2:51:32 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Jul 10, 2012 2:51:32 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
Jul 10, 2012 2:51:32 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Jul 10, 2012 2:51:32 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
Jul 10, 2012 2:51:32 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Jul 10, 2012 2:51:32 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 1
Jul 10, 2012 2:51:32 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: false
Jul 10, 2012 2:51:32 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [com.sybase.jdbc4.jdbc.SybDriver] at URL [***]
Jul 10, 2012 2:51:32 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=***, password=****}
Jul 10, 2012 2:51:33 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.SybaseASE15Dialect
Jul 10, 2012 2:51:33 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
Jul 10, 2012 2:51:33 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Hibernate: select contact0_.contactID as contactID0_, contact0_.companyID as companyID0_, contact0_.contactName as contactName0_, contact0_.email as email0_, contact0_.ext as ext0_, contact0_.fax as fax0_, contact0_.firstName as firstName0_, contact0_.lastName as lastName0_, contact0_.loginName as loginName0_, contact0_.passCode as passCode0_, contact0_.phone as phone0_, contact0_.status as status0_ from Contact contact0_
Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 207, SQLState: ZZZZZ
Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Invalid column name 'status'.

Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 207, SQLState: ZZZZZ
Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Invalid column name 'phone'.

Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 207, SQLState: ZZZZZ
Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Invalid column name 'passCode'.

Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 207, SQLState: ZZZZZ
Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Invalid column name 'loginName'.

Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 207, SQLState: ZZZZZ
Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Invalid column name 'lastName'.

Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 207, SQLState: ZZZZZ
Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Invalid column name 'firstName'.

Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 207, SQLState: ZZZZZ
Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Invalid column name 'fax'.

Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 207, SQLState: ZZZZZ
Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Invalid column name 'ext'.

Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 207, SQLState: ZZZZZ
Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Invalid column name 'email'.

Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 207, SQLState: ZZZZZ
Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Invalid column name 'contactName'.

Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 207, SQLState: ZZZZZ
Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Invalid column name 'companyID'.

Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 207, SQLState: ZZZZZ
Jul 10, 2012 2:51:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Invalid column name 'contactID'.

Exception in thread "main" org.hibernate.exception.GenericJDBCException: Invalid column name 'status'.

   at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
   at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
   at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
   at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
   at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
   at $Proxy9.executeQuery(Unknown Source)
   at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
   at org.hibernate.loader.Loader.doQuery(Loader.java:829)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)
   at org.hibernate.loader.Loader.doList(Loader.java:2438)
   at org.hibernate.loader.Loader.doList(Loader.java:2424)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2254)
   at org.hibernate.loader.Loader.list(Loader.java:2249)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470)
   at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
   at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
   at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1248)
   at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
   at javaapplication2.JavaApplication2.listContactsHibernate(JavaApplication2.java:36)
   at javaapplication2.JavaApplication2.main(JavaApplication2.java:20)
Caused by: java.sql.SQLException: Invalid column name 'status'.

   at com.sybase.jdbc4.jdbc.SybConnection.getAllExceptions(Unknown Source)
   at com.sybase.jdbc4.jdbc.SybStatement.handleSQLE(Unknown Source)
   at com.sybase.jdbc4.jdbc.SybStatement.nextResult(Unknown Source)
   at com.sybase.jdbc4.jdbc.SybStatement.nextResult(Unknown Source)
   at com.sybase.jdbc4.jdbc.SybStatement.queryLoop(Unknown Source)
   at com.sybase.jdbc4.jdbc.SybStatement.executeQuery(Unknown Source)
   at com.sybase.jdbc4.jdbc.SybPreparedStatement.executeQuery(Unknown Source)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:601)
   at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
   ... 16 more


Ont thing I noticed in the log output is the hibernate sql query that is generated. It shows select contact0_.contactID as contactID0_, contact0_.companyID as companyID0_.... I am confused about "contact0_" -- where is this coming from? I don't see an alias being set (which would of course cause it to fail).

Your help would be greatly appreciated.


Top
 Profile  
 
 Post subject: Re: Invalid Column Name errir
PostPosted: Wed Jul 11, 2012 3:03 pm 
Newbie

Joined: Wed Jul 11, 2012 2:51 pm
Posts: 1
You can cross verify with the .hbm file entries for the columns and try out.

_________________
Thanks
RR


Top
 Profile  
 
 Post subject: Re: Invalid Column Name errir
PostPosted: Wed Jul 11, 2012 3:45 pm 
Newbie

Joined: Tue Jul 10, 2012 4:00 pm
Posts: 2
There is no hbm file, I am using annotations. But to answer your question, I also tried it with an hbm file and got the same result.

This seems to be related to the Sybase JDBC driver. I tried two versions of this driver, 6 and 7, and both failed with the same error. In contrast, I ran the same code against MySQL and its JDBC driver and it worked.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 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.