-->
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.  [ 5 posts ] 
Author Message
 Post subject: SQLException Column 'id' Not Found
PostPosted: Fri Jul 30, 2004 3:45 pm 
Newbie

Joined: Fri Jul 30, 2004 3:11 pm
Posts: 18
I am using Hibernate 2.2.2 in Eclipse w/Hibernate Synchronizer going against MySQL 4.1.3 using the latest rev of their type 4 jdbc driver.

It was rather easy for me to map a table, populate a class and persist it.

When I try and retrieve the classes with a query that has no where clause, it works, and I get my Users. As soon as I stipulate a where clause, I get the following error:

SEVERE: Could not execute query
java.sql.SQLException: Column 'id' not found.
at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:2315)
at com.mysql.jdbc.ResultSet.getLong(ResultSet.java:1352)
at net.sf.hibernate.type.LongType.get(LongType.java:1
at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:62)
at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:53)
at net.sf.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:352)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:203)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:955)
at net.sf.hibernate.loader.Loader.list(Loader.java:946)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:834)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1536)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at org.apache.jsp.ProcessRegistration_jsp._jspService(ProcessRegistration_jsp.java:85)


Here is my User class:

package com.ontometrics.web.test;

import com.ontometrics.web.test.base.BaseUser;

/**
* This is the object class that relates to the User table.
* Any customizations belong here.
*/
public class User extends BaseUser {
/*[CONSTRUCTOR MARKER BEGIN]*/
public User () {}

/**
* Constructor for primary key
*/
public User (java.lang.Long _id) {
super(_id);
}

/**
* Constructor for required fields
*/
public User (
java.lang.Long _id,
java.lang.String _password,
java.lang.String _last,
java.lang.String _first,
java.lang.String _email) {

super (
_id,
_password,
_last,
_first,
_email);
}

/*[CONSTRUCTOR MARKER END]*/

}

My schema is:

+------------+------------------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------------------------+------+-----+---------+----------------+
| id | bigint(11) | | PRI | NULL | auto_increment |
| first | varchar(32) | | | | |
| last | varchar(32) | | | | |
| email | varchar(32) | | | | |
| experience | tinyint(3) unsigned zerofill | YES | | NULL | |
| password | varchar(32) | | | | |
+------------+------------------------------+------+-----+---------+----------------+
6 rows in set (0.05 sec)

and the hbm file looks like this:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping package="com.ontometrics.web.test">
<class
name="User"
table="User"
>
<id
name="Id"
type="java.lang.Long"
column="id"
>
<generator class="vm"/>
</id>

<property
name="Password"
column="password"
type="string"
not-null="true"
length="32"
/>
<property
name="Last"
column="last"
type="string"
not-null="true"
length="32"
/>
<property
name="First"
column="first"
type="string"
not-null="true"
length="32"
/>
<property
name="Email"
column="email"
type="string"
not-null="true"
length="32"
/>
<!-- please tell Joe Hudson that the type 'tinyint unsigned' could not be resolved.. defaulting to java.lang.String -->
<property
name="Experience"
column="experience"
type="java.lang.String"
not-null="false"
length="3"
/>


</class>
</hibernate-mapping>

Reading the stack trace, where it says it can't find the column, you would think that any attempt to load an instance using the database metadata would fail.

I thought it might have been because I was using an auto_increment. I scrapped that and the error is still coming up. Of course, if I just execute using JDBC, works fine, I can call getLong("id") and it works.

Thanks.


Top
 Profile  
 
 Post subject: Few more tidbits
PostPosted: Fri Jul 30, 2004 4:02 pm 
Newbie

Joined: Fri Jul 30, 2004 3:11 pm
Posts: 18
When I do this:

Code:
         User u = (User) dbSession.load(User.class, new Integer(1));
         log.info("User email = " + u.getEmail());


I get this error:

Code:
WARNING: SQL Error: 0, SQLState: S0022
Jul 30, 2004 12:50:23 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Column 'email0_' not found.
Jul 30, 2004 12:50:23 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 0, SQLState: S0022
Jul 30, 2004 12:50:23 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Column 'email0_' not found.
Jul 30, 2004 12:50:23 PM net.sf.hibernate.JDBCException <init>
SEVERE: could not load: [com.ontometrics.web.test.User#1]
java.sql.SQLException: Column 'email0_' not found.
   at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:2315)
   at com.mysql.jdbc.ResultSet.getString(ResultSet.java:1830)
   at net.sf.hibernate.type.StringType.get(StringType.java:18)
   at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:62)
   at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:53)
   at net.sf.hibernate.type.AbstractType.hydrate(AbstractType.java:66)
   at net.sf.hibernate.loader.Loader.hydrate(Loader.java:611)
   at net.sf.hibernate.loader.Loader.loadFromResultSet(Loader.java:552)
   at net.sf.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:511)
   at net.sf.hibernate.loader.Loader.getRow(Loader.java:426)
   at net.sf.hibernate.loader.Loader.doQuery(Loader.java:209)
   at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
   at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:836)
   at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:856)
   at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:59)
   at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:51)
   at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:419)
   at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2106)
   at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1980)
   at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1909)
   at com.ontometrics.web.test.ProcessRegistration.testQuery(ProcessRegistration.java:98)


One more thing: once in a blue moon, when I refresh the HTML page, it reloads all the Hibernate stuff and it works, doesn't throw an exception. That made me think maybe it was something goofy from me not closing sessions or something, but I am. Here is my config file:

Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
    PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
   <session-factory>
      <!-- local connection properties -->
      <property name="hibernate.connection.url">
         jdbc:mysql://localhost/test
      </property>
      <property name="hibernate.connection.driver_class">
         com.mysql.jdbc.Driver
      </property>
      <property name="hibernate.connection.username">root</property>
      <property name="hibernate.connection.password">ope18195</property>
      <!-- property name="hibernate.connection.pool_size"></property -->
      <!-- dialect for MySQL -->
      <property name="dialect">
         net.sf.hibernate.dialect.MySQLDialect
      </property>
      <property name="hibernate.show_sql">false</property>
      <property name="hibernate.use_outer_join">true</property>
      <property name="hibernate.transaction.factory_class">
         net.sf.hibernate.transaction.JTATransactionFactory
      </property>
      <property name="jta.UserTransaction">
         java:comp/UserTransaction
      </property>
      <mapping resource="com/ontometrics/web/test/User.hbm" />
   </session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject: One more thing!
PostPosted: Fri Jul 30, 2004 4:06 pm 
Newbie

Joined: Fri Jul 30, 2004 3:11 pm
Posts: 18
At first, when I was trying to query with a where clause on the email, I was using HQL and had:

Code:
q = dbSession.createQuery("SELECT u FROM User AS u WHERE u.email = :email");


and that would fail saying it couldn't find the column, but when I changed it to:

Code:
q = dbSession.createQuery("SELECT u FROM User AS u WHERE u.Email = :email");


it worked (??).

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 30, 2004 6:31 pm 
Newbie

Joined: Fri Jul 30, 2004 3:11 pm
Posts: 18
Trying to isolate this problem, I've come to the rather bizarre conclusion: it has something to do with some state that is hanging around. If I close Eclipse, then open it and run the code, it works. If I run it again right away, it fails. I have looked everywhere I could: at the session initialization, at using transactions, and at making sure the sessions are getting closed. I am seeing this warning:

Code:
WARNING: afterTransactionCompletion() was never called


What I'm doing here is I have an HTML form that posts to a servlet. I am switching back and forth between the browser and eclipse. The autoupdating in Tomcat (5.1 BTW) is definitely working as I can add a line to the servlet and it is immediately reflected.


Top
 Profile  
 
 Post subject: Truly Bizarre
PostPosted: Sat Jul 31, 2004 4:56 am 
Newbie

Joined: Fri Jul 30, 2004 3:11 pm
Posts: 18
Code:
DEBUG - HQL: SELECT u FROM com.ontometrics.web.test.User AS u WHERE u.Email = :email
DEBUG - SQL: select user0_.user_id as user_id, user0_.password as password, user0_.last as last, user0_.first as first, user0_.email as email, user0_.experience as experience from User user0_ where (user0_.email=? )
DEBUG - select user0_.user_id as user_id, user0_.password as password, user0_.last as last, user0_.first as first, user0_.email as email, user0_.experience as experience from User user0_ where (user0_.email=? )
DEBUG - about to open: 0 open PreparedStatements, 0 open ResultSets
Hibernate: select user0_.user_id as user_id, user0_.password as password, user0_.last as last, user0_.first as first, user0_.email as email, user0_.experience as experience from User user0_ where (user0_.email=? )
DEBUG - preparing statement
DEBUG - Connection preparing statement
DEBUG - binding 'bill@mickeysoft.com' to parameter: 1
DEBUG - Results from batcher: com.mysql.jdbc.ResultSetMetaData@cdd63c - Field level information:
   test . user0_(user) . password(password), Mysql type: 253
   test . user0_(user) . last(last), Mysql type: 253
   test . user0_(user) . first(first), Mysql type: 253


You can see that it is translating the HQL to SQL properly, but then, for some reason, it returns a result set that only has three fields. I tried to walk through this in the debugger. If I take the query and feed it to MySQL at the command line, it returns the expected results.


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