Hi Folks,
 
We have a table 'dummy' with no primary key (playing w/ the dealt cards) which upon trying to perform an insert, we get an unexpected error from mysql
 
    java.sql.SQLException: Column not found,  message from server: "Unknown column 'hostName' in 'field list'"
 
For other tables with primary keys, we do not see the issue.
 
Judging from the log files, it seems as if 'hostName' is appended to the insert statement, which seems quite odd......
 
14:35:41,640 DEBUG SessionFactoryImpl:526 - prepared statement get: insert into dummy (host_name, update_date, hostName) values (?, ?, ?)
 
...because the schema looks like this.....
 
create table dummy ( host_name int(11) NOT NULL , update_date datetime NOT NULL ) ;
We are using MySQL 4.0.15, Hibernate 2.0.3 and the mysql-connector.jar 3.0.8 (stable).
 
Anyone run into this? 
 
Stack Trace, configuration files and source code are below:
 
14:35:41,640 DEBUG EntityPersister:464 - Inserting entity: [EMAIL PROTECTED]
14:35:41,640 DEBUG BatcherImpl:166 - about to open: 0 open PreparedStatements, 0 open ResultSets
14:35:41,640 DEBUG SessionFactoryImpl:526 - prepared statement get: insert into dummy (host_name, update_date, hostName) values (?, ?, ?)
Hibernate: insert into dummy (host_name, update_date, hostName) values (?, ?, ?)
14:35:41,640 DEBUG SessionFactoryImpl:536 - preparing statement
14:35:41,734 DEBUG EntityPersister:366 - Dehydrating entity: [EMAIL PROTECTED]
14:35:41,781 DEBUG JDBCExceptionReporter:36 - SQL Exception
java.sql.SQLException: Column not found,  message from server: "Unknown column 'hostName' in 'field list'"
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1651)
 at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:889)
 at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:956)
 at com.mysql.jdbc.Connection.execSQL(Connection.java:1874)
 at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1700)
 at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1569)
 at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
 at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:478)
 at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:454)
 at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:20)
 at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2100)
 at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2061)
 at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2005)
 at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:57)
 at QuickTest.endTransaction(QuickTest.java:69)
 at QuickTest.main(QuickTest.java:30)
 
------------------------------------------------------------------------------------------------------------------------------------------------------
hibernate.cfg.xml:
 
<?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>
        <property name="connection.datasource">java:comp/env/jdbc/dummy</property>
        <property name="show_sql">true</property>
        <property name="use_outer_join">true</property>
        <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
        <!-- Mapping files -->
         <mapping resource="Dummy.hbm.xml"/>
    </session-factory>
</hibernate-configuration>
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Dummy.hbm.xml:
 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.Dummy" table="dummy">
 <composite-id unsaved-value="none">
  <key-property name="hostName" />
  </composite-id>
<property column="host_name" length="11" name="hostName" not-null="true" type="java.lang.Integer"/>
<property column="update_date" length="19" name="updateDate" not-null="true" type="java.util.Date"/>
</class>
</hibernate-mapping>
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Dummy.java:
 
package com;
 
import java.io.Serializable;
import java.util.Date;
import org.apache.commons.lang.builder.ToStringBuilder;
 
/** @author Hibernate CodeGenerator */
public class Dummy implements Serializable {
 
    /** persistent field */
    private Integer hostName;
 
    /** persistent field */
    private Date updateDate;
 
    /** full constructor */
    public Dummy(Integer hostName, Date updateDate) {
        this.hostName = hostName;
        this.updateDate = updateDate;
    }
 
    /** default constructor */
    public Dummy() {
    }
 
    public Integer getHostName() {
        return this.hostName;
    }
 
    public void setHostName(Integer hostName) {
        this.hostName = hostName;
    }
 
    public Date getUpdateDate() {
        return this.updateDate;
    }
 
    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }
 
    public String toString() {
        return new ToStringBuilder(this)
            .toString();
    }
 
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------
QuickTest.java:
 

import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;
import java.util.Date;
import com.Dummy;
 
import test.jndi.JNDIUnitTestHelper;
 

public class QuickTest {
 
    private SessionFactory sessionFactory;
    private Session session;
    private Transaction transaction;
 
    public static void main(String[] args) throws Exception {
 

        // SET UP JNDI HERE.....
          if (JNDIUnitTestHelper.notInitialized()) {
                JNDIUnitTestHelper.init("jndi");
            }
 

        QuickTest qTest = new QuickTest();
        try {
            qTest.initHibernate();
            qTest.beginTransaction();
            qTest.test();
            qTest.endTransaction(true);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    public void test()    throws Exception
    {
        Dummy dummy = new Dummy();
        dummy.setHostName(new Integer(2));
        dummy.setUpdateDate(new Date());
        session.save(dummy);
 

    }
    // Helper Methods
    private void initHibernate()
            throws HibernateException {
 
        Configuration cfg = new Configuration();
 
        cfg.configure();
 
        sessionFactory = cfg.buildSessionFactory();
 
    }
 
    private void beginTransaction()
            throws HibernateException {
 
        session = sessionFactory.openSession();
        transaction = session.beginTransaction();
    }
 
    private void endTransaction(boolean commit)
            throws HibernateException {
 
        if (commit) {
            transaction.commit();
        } else {
            // Don't commit the transaction, can be faster for read-only operations
            transaction.rollback();
        }
        session.close();
    }
 
}
 
 

 

Reply via email to