-->
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: Problems mapping to an existing database
PostPosted: Wed Dec 10, 2003 3:17 pm 
Newbie

Joined: Thu Nov 27, 2003 5:27 pm
Posts: 10
Hello. I'm trying to wrap Hibernate around an existing MySQL database and am having some serious growing pains, being new to Hibernate. I keep bumping into unexpected issues, and I've gotten stuck. Let's start with the snippets:

User table DDL
Code:
CREATE TABLE `users` (
  `id` int(11) NOT NULL auto_increment,
  `username` varchar(15) default NULL,
  `password` varchar(15) default NULL,
  `violations` int(11) default NULL,
  `fname` varchar(20) default NULL,
  `lname` varchar(25) default NULL,
  `addr1` varchar(25) default NULL,
  `addr2` varchar(25) default NULL,
  `city` varchar(15) default NULL,
  `state` char(2) default NULL,
  `zip` varchar(10) default NULL,
  `country` varchar(15) default NULL,
  `phone` varchar(25) default NULL,
  `fax` varchar(25) default NULL,
  `email` varchar(40) default NULL,
  `regdate` datetime default NULL,
  `lastchangedate` datetime default NULL,
  `emailpref` smallint(6) default NULL,
  `months` int(11) default NULL,
  `amount` double default NULL,
  `accepteddisclaimer` datetime default NULL,
  `expiration` datetime default NULL,
  `ackedmsgs` varchar(200) default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `id` (`id`),
  UNIQUE KEY `UQ__users__0EA330E9` (`username`),
  UNIQUE KEY `PK__users__0DAF0CB0` (`id`)
) TYPE=MyISAM
User.hbm.xml
Code:
<?xml version="1.0"?>
<!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.greymatter.optioninsight.hibernate.User" table="users">
        <id name="id">
            <generator class="identity"/>
        </id>
        <property name="acceptedDisclaimer" column="accepteddisclaimer"/>
        <property name="ackedMsgs" column="ackedmsgs"/>
        <property name="addr1"/>
        <property name="addr2"/>
        <property name="amount"/>
        <property name="city"/>
        <property name="country"/>
        <property name="email"/>
        <property name="emailPref" column="emailpref"/>
        <property name="expiration"/>
        <property name="fax"/>
        <property name="fname"/>
        <property name="lastChangeDate" column="lastchangedate"/>
        <property name="lname"/>
        <property name="months"/>
        <property name="password"/>
        <property name="phone"/>
        <property name="regDate" column="regdate"/>
        <property name="state"/>
        <property name="username" unique="true"/>
        <property name="violations"/>
        <property name="zip"/>

<!--
        <set name="machines" table="UserMachine" inverse="true" lazy="true">
           <key column="userid"/>
           <one-to-many class="com.greymatter.optioninsight.hibernate.Machine"/>
        </set>
-->
       
<!--
        <set name="sessions" table="session" inverse="true" lazy="true">
           <key column="userid"/>
           <one-to-many class="com.greymatter.optioninsight.hibernate.UserSession"/>
        </set>
-->
    </class>

</hibernate-mapping>
<!-- parsed in 0ms -->
User.java
Code:
/*
* Created on Nov 28, 2003
*/
package com.greymatter.optioninsight.hibernate;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
* This is a Data Transfer Object
*
* @author Lee
*/
public class User {

   private static Log LOG = LogFactory.getLog(User.class);

   private Long id;
   private String username;
   private String password;
   private BigInteger violations;
   private String fname;
   private String lname;
   private String addr1;
   private String addr2;
   private String city;
   private String state;
   private String zip;
   private String country;
   private String phone;
   private String fax;
   private String email;
   private Date regDate;
   private Date lastChangeDate;
   private BigInteger emailPref;
   private BigInteger months;
   private BigDecimal amount;
   private Date acceptedDisclaimer;
   private Date expiration;
   private String ackedMsgs;
//   private Set sessions;
   
   public User() {
   }

... standard getters and setters removed to save space ...
}
UserTest.java
Code:
/*
* Created on Nov 28, 2003
*
*/
package test.com.greymatter.optioninsight.hibernate;

import java.math.BigInteger;
import java.util.List;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import net.sf.hibernate.Hibernate;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.greymatter.optioninsight.GLOBALS;
import com.greymatter.optioninsight.hibernate.User;

/**
* @author Lee
*/
public class UserTest extends TestCase {

   private static Log LOG = LogFactory.getLog(UserTest.class);
   private Session session = null;

   /**
    * Constructor for UserTest.
    * @param arg0
    */
   public UserTest(String arg0) {
      super(arg0);
   }

   /*
    * @see TestCase#setUp()
    */
   protected void setUp() throws Exception {
      super.setUp();
      session = GLOBALS.getSession();
   }

   /*
    * @see TestCase#tearDown()
    */
   protected void tearDown() throws Exception {
      super.tearDown();
      session.disconnect();
      GLOBALS.HibernateSessionFactory.close();
   }

   public void testAddUser() {
      try {
         LOG.debug("testAddUser");
         // confirm it doesn't exist
         List users = session.find("from User where username = ?", "testUsername", Hibernate.STRING);
         assertEquals(0, users.size());         
         // now add it
         User user = new User();
         user.setFname("testFirst");
         user.setLname("testLast");
         user.setUsername("testUsername");
         user.setPassword("testPassword");
         user.setEmail("testEmail@testDomain.com");
         session.save(user);
         LOG.debug("id of added item is " + user.getId());
         // confirm addition
         users = session.find("from User where username = ?", "testUsername", Hibernate.STRING);
         assertEquals(1, users.size());         
      } catch( HibernateException he ) {
         LOG.error("Exception", he);
         fail("exception");
      }
   }

   public void testLoadUser() {
      try {
         LOG.debug("testLoadUser");
         
         User user = new User();
         LOG.debug("a");
         session.load(user, new Long(42));
         LOG.debug("b");
         LOG.debug("id of loaded item is " + user.getId());
         LOG.debug("username of loaded item is " + user.getUsername());
         LOG.debug("email of loaded item is " + user.getEmail());
      } catch( Exception he ) {
         LOG.error("Exception", he);
         fail("exception");
      }
      LOG.debug("c");
   }

   public void testDeleteUser() {
      try {
         LOG.debug("testDeleteUser");
         // confirm it exists
         List users = session.find("from User where username = ?", "testUsername", Hibernate.STRING);
         assertEquals(1, users.size());
         // now delete it         
         users = session.find("from User where username = ?", "testUsername", Hibernate.STRING);
         LOG.debug("found " + users.size());
         User user = (User)users.get(0);
         LOG.debug("id of first item is " + user.getId());
         //////////session.delete(user);
         session.flush();
         // confirm deletion
         users = session.find("from User where username = ?", "testUsername", Hibernate.STRING);
         assertEquals(0, users.size());
      } catch( HibernateException he ) {
         LOG.error("Exception", he);
         fail("exception");
      }
   }
   

   /**
    * Assembles and returns a test suite for
    * all the test methods of this test case.
    *
    * @return A non-null test suite.
    */
   public static Test suite() {
      // Reflection is used here to add all
      // the testXXX() methods to the suite.
      TestSuite suite = new TestSuite(UserTest.class);
      return suite;
   }
}
And now the output from the test script
Code:
13:44:48,110  INFO Environment:403 - Hibernate 2.0.3
13:44:48,180  INFO Environment:437 - loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.gjt.mm.mysql.Driver, hibernate.cglib.use_reflection_optimizer=false, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.query.imports=net.sf.hibernate.test, net.sf.hibernate.eg, hibernate.proxool.pool_alias=pool1, hibernate.connection.username=qwe, hibernate.connection.url=jdbc:mysql://192.168.1.60:3306/optioninsight, hibernate.show_sql=true, hibernate.connection.password=zxc, hibernate.statement_cache.size=25, hibernate.connection.pool_size=1}
13:44:48,190  INFO Environment:451 - using java.io streams to persist binary types
13:44:48,200  INFO Environment:462 - JVM proxy support: true
13:44:48,200  INFO Configuration:283 - Mapping resource: com/greymatter/optioninsight/hibernate/User.hbm.xml
13:44:49,122  INFO Binder:178 - Mapping class: com.greymatter.optioninsight.hibernate.User -> users
13:44:49,272  INFO Configuration:283 - Mapping resource: com/greymatter/optioninsight/hibernate/Machine.hbm.xml
13:44:49,342  INFO Binder:178 - Mapping class: com.greymatter.optioninsight.hibernate.Machine -> machines
13:44:49,362  INFO Configuration:283 - Mapping resource: com/greymatter/optioninsight/hibernate/UserSession.hbm.xml
13:44:49,402  INFO Binder:178 - Mapping class: com.greymatter.optioninsight.hibernate.UserSession -> session
13:44:49,422  INFO Configuration:492 - processing one-to-many association mappings
13:44:49,422  INFO Configuration:503 - processing foreign key constraints
13:44:49,582  INFO SessionFactoryImpl:132 - building session factory
13:44:49,602  INFO Dialect:83 - Using dialect: net.sf.hibernate.dialect.MySQLDialect
13:44:49,612  INFO DriverManagerConnectionProvider:41 - Hibernate connection pool size: 1
13:44:49,622  INFO DriverManagerConnectionProvider:70 - using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://192.168.1.60:3306/optioninsight
13:44:49,622  INFO DriverManagerConnectionProvider:71 - connection properties: {user=qwe, password=zxc}
13:44:49,632  INFO PreparedStatementCache:60 - prepared statement cache size: 25
13:44:49,632  INFO SessionFactoryImpl:162 - Use outer join fetching: true
13:44:49,853  INFO SessionFactoryImpl:185 - Use scrollable result sets: true
13:44:49,863  INFO SessionFactoryImpl:194 - echoing all SQL to stdout
13:44:50,574  INFO SessionFactoryObjectFactory:82 - no JDNI name configured
13:44:50,574  INFO SessionFactoryImpl:269 - Query language substitutions: {no='N', true=1, yes='Y', false=0}
13:44:50,634 DEBUG UserTest:65 - testAddUser
Hibernate: select user0_.id as id, user0_.accepteddisclaimer as accepted2_, user0_.ackedmsgs as ackedmsgs, user0_.addr1 as addr1, user0_.addr2 as addr2, user0_.amount as amount, user0_.city as city, user0_.country as country, user0_.email as email, user0_.emailpref as emailpref, user0_.expiration as expiration, user0_.fax as fax, user0_.fname as fname, user0_.lastchangedate as lastcha14_, user0_.lname as lname, user0_.months as months, user0_.password as password, user0_.phone as phone, user0_.regdate as regdate, user0_.state as state, user0_.username as username, user0_.violations as violations, user0_.zip as zip from users user0_ where (username=? )
13:44:50,734  INFO SessionFactoryImpl:684 - closing
13:44:50,734  INFO PreparedStatementCache:210 - cleaning up prepared statement cache
13:44:50,734  INFO DriverManagerConnectionProvider:144 - cleaning up connection pool: jdbc:mysql://192.168.1.60:3306/optioninsight
13:44:50,744 DEBUG UserTest:89 - testLoadUser
13:44:50,744 DEBUG UserTest:92 - a
Hibernate: select user0_.id as id, user0_.accepteddisclaimer as accepted2_, user0_.ackedmsgs as ackedmsgs, user0_.addr1 as addr1, user0_.addr2 as addr2, user0_.amount as amount, user0_.city as city, user0_.country as country, user0_.email as email, user0_.emailpref as emailpref, user0_.expiration as expiration, user0_.fax as fax, user0_.fname as fname, user0_.lastchangedate as lastcha14_, user0_.lname as lname, user0_.months as months, user0_.password as password, user0_.phone as phone, user0_.regdate as regdate, user0_.state as state, user0_.username as username, user0_.violations as violations, user0_.zip as zip from users user0_ where user0_.id=?
13:44:50,854 ERROR UserTest:99 - Exception
java.io.EOFException
   at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2165)
   at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2634)
   at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:734)
   at java.io.ObjectInputStream.<init>(ObjectInputStream.java:253)
   at org.apache.commons.lang.SerializationUtils.deserialize(SerializationUtils.java:164)
   at org.apache.commons.lang.SerializationUtils.deserialize(SerializationUtils.java:191)
   at net.sf.hibernate.type.SerializableType.fromBytes(SerializableType.java:72)
   at net.sf.hibernate.type.SerializableType.get(SerializableType.java:35)
   at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:59)
   at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:51)
   at net.sf.hibernate.type.AbstractType.hydrate(AbstractType.java:66)
   at net.sf.hibernate.loader.Loader.hydrate(Loader.java:419)
   at net.sf.hibernate.loader.Loader.loadFromResultSet(Loader.java:373)
   at net.sf.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:342)
   at net.sf.hibernate.loader.Loader.getRow(Loader.java:281)
   at net.sf.hibernate.loader.Loader.doFind(Loader.java:159)
   at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:587)
   at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:42)
   at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:396)
   at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:1889)
   at net.sf.hibernate.impl.SessionImpl.doLoadByObject(SessionImpl.java:1734)
   at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1683)
   at test.com.greymatter.optioninsight.hibernate.UserTest.testLoadUser(UserTest.java:93)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
rethrown as
org.apache.commons.lang.SerializationException
   at org.apache.commons.lang.SerializationUtils.deserialize(SerializationUtils.java:170)
   at org.apache.commons.lang.SerializationUtils.deserialize(SerializationUtils.java:191)
   at net.sf.hibernate.type.SerializableType.fromBytes(SerializableType.java:72)
   at net.sf.hibernate.type.SerializableType.get(SerializableType.java:35)
   at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:59)
   at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:51)
   at net.sf.hibernate.type.AbstractType.hydrate(AbstractType.java:66)
   at net.sf.hibernate.loader.Loader.hydrate(Loader.java:419)
   at net.sf.hibernate.loader.Loader.loadFromResultSet(Loader.java:373)
   at net.sf.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:342)
   at net.sf.hibernate.loader.Loader.getRow(Loader.java:281)
   at net.sf.hibernate.loader.Loader.doFind(Loader.java:159)
   at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:587)
   at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:42)
   at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:396)
   at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:1889)
   at net.sf.hibernate.impl.SessionImpl.doLoadByObject(SessionImpl.java:1734)
   at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1683)
   at test.com.greymatter.optioninsight.hibernate.UserTest.testLoadUser(UserTest.java:93)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
Caused by: java.io.EOFException
   at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2165)
   at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2634)
   at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:734)
   at java.io.ObjectInputStream.<init>(ObjectInputStream.java:253)
   at org.apache.commons.lang.SerializationUtils.deserialize(SerializationUtils.java:164)
   ... 35 more
rethrown as
net.sf.hibernate.type.SerializationException: Could not deserialize a serializable property:
   at net.sf.hibernate.type.SerializableType.fromBytes(SerializableType.java:75)
   at net.sf.hibernate.type.SerializableType.get(SerializableType.java:35)
   at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:59)
   at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:51)
   at net.sf.hibernate.type.AbstractType.hydrate(AbstractType.java:66)
   at net.sf.hibernate.loader.Loader.hydrate(Loader.java:419)
   at net.sf.hibernate.loader.Loader.loadFromResultSet(Loader.java:373)
   at net.sf.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:342)
   at net.sf.hibernate.loader.Loader.getRow(Loader.java:281)
   at net.sf.hibernate.loader.Loader.doFind(Loader.java:159)
   at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:587)
   at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:42)
   at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:396)
   at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:1889)
   at net.sf.hibernate.impl.SessionImpl.doLoadByObject(SessionImpl.java:1734)
   at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1683)
   at test.com.greymatter.optioninsight.hibernate.UserTest.testLoadUser(UserTest.java:93)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
Caused by: org.apache.commons.lang.SerializationException
   at org.apache.commons.lang.SerializationUtils.deserialize(SerializationUtils.java:170)
   at org.apache.commons.lang.SerializationUtils.deserialize(SerializationUtils.java:191)
   at net.sf.hibernate.type.SerializableType.fromBytes(SerializableType.java:72)
   ... 33 more
Caused by: java.io.EOFException
   at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2165)
   at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2634)
   at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:734)
   at java.io.ObjectInputStream.<init>(ObjectInputStream.java:253)
   at org.apache.commons.lang.SerializationUtils.deserialize(SerializationUtils.java:164)
   ... 35 more
13:44:50,894  INFO SessionFactoryImpl:684 - closing
13:44:50,894  INFO PreparedStatementCache:210 - cleaning up prepared statement cache
13:44:50,924  INFO DriverManagerConnectionProvider:144 - cleaning up connection pool: jdbc:mysql://192.168.1.60:3306/optioninsight
13:44:50,944 DEBUG UserTest:107 - testDeleteUser
Hibernate: select user0_.id as id, user0_.accepteddisclaimer as accepted2_, user0_.ackedmsgs as ackedmsgs, user0_.addr1 as addr1, user0_.addr2 as addr2, user0_.amount as amount, user0_.city as city, user0_.country as country, user0_.email as email, user0_.emailpref as emailpref, user0_.expiration as expiration, user0_.fax as fax, user0_.fname as fname, user0_.lastchangedate as lastcha14_, user0_.lname as lname, user0_.months as months, user0_.password as password, user0_.phone as phone, user0_.regdate as regdate, user0_.state as state, user0_.username as username, user0_.violations as violations, user0_.zip as zip from users user0_ where (username=? )
Hibernate: select user0_.id as id, user0_.accepteddisclaimer as accepted2_, user0_.ackedmsgs as ackedmsgs, user0_.addr1 as addr1, user0_.addr2 as addr2, user0_.amount as amount, user0_.city as city, user0_.country as country, user0_.email as email, user0_.emailpref as emailpref, user0_.expiration as expiration, user0_.fax as fax, user0_.fname as fname, user0_.lastchangedate as lastcha14_, user0_.lname as lname, user0_.months as months, user0_.password as password, user0_.phone as phone, user0_.regdate as regdate, user0_.state as state, user0_.username as username, user0_.violations as violations, user0_.zip as zip from users user0_ where (username=? )
13:44:51,074 DEBUG UserTest:113 - found 1
13:44:51,074 DEBUG UserTest:115 - id of first item is 977
Hibernate: select user0_.id as id, user0_.accepteddisclaimer as accepted2_, user0_.ackedmsgs as ackedmsgs, user0_.addr1 as addr1, user0_.addr2 as addr2, user0_.amount as amount, user0_.city as city, user0_.country as country, user0_.email as email, user0_.emailpref as emailpref, user0_.expiration as expiration, user0_.fax as fax, user0_.fname as fname, user0_.lastchangedate as lastcha14_, user0_.lname as lname, user0_.months as months, user0_.password as password, user0_.phone as phone, user0_.regdate as regdate, user0_.state as state, user0_.username as username, user0_.violations as violations, user0_.zip as zip from users user0_ where (username=? )
13:44:51,104  INFO SessionFactoryImpl:684 - closing
13:44:51,104  INFO PreparedStatementCache:210 - cleaning up prepared statement cache
13:44:51,114  INFO DriverManagerConnectionProvider:144 - cleaning up connection pool: jdbc:mysql://192.168.1.60:3306/optioninsight
One of the issues I've faced is that my database can contain nulls in many columns. I learned that I had to change a number of primitive types to nullable types such as BigInteger and BigDecimal. The thing that's got me stuck now is the current exception, which seems very odd. I know that the item with key value of 42 exists in the table, so I'm not sure why it's failing. And why am I getting an EOFException of all things? That seems very strange.

I apologize for the length of this message, but I've hopefully provided all the details necessary.

Thank you in advance for your help,
Lee Grey

_________________
http://www.URLinOne.com
http://www.AuctionRelay.com
http://www.OptionInsight.com


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 5:28 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Search into the forum 'EOFException' you might find something useful (there isn't lot's of good news however ;-( )

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 12:18 am 
Newbie

Joined: Thu Nov 27, 2003 5:27 pm
Posts: 10
Yeesh, I'm not even sure what to make of all that.

Any thoughts on a work-around? Am I doing anything questionable? It all seems so simple and straightforward, that I don't even know what to change (other than removing Hibernate from the project, which I don't want to have to do.).

Thanks,
Lee

_________________
http://www.URLinOne.com
http://www.AuctionRelay.com
http://www.OptionInsight.com


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 12:24 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
As with many problems:

(1) make it work using direct JDBC
(2) make it work in Hibernate (you may need to refer to the Hibernate source)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 6:11 am 
Newbie

Joined: Thu Nov 27, 2003 5:27 pm
Posts: 10
I copied the SQL query that Hibernate generated, took the JDBC connection from Hibernate's session.connection(), and created a PreparedStatement. I set the parameter to the same value as I was giving Hibernate, and the query worked as expected.

I decided to try loading a row that I generated in Hibernate, as opposed to ones that already existed in my database. It turns out that I WAS able to load a new row, however, most of its columns were null. So, I started adding data to the new row until it broke.

The end result was that the type BigInteger in my User class was the problem. All I had to do was change it to Integer, and life is good again.

I would like to understand what happened. Both Integer and BigInteger implement Serializable. The glaring thing I see is that BigInteger does not have a constructor that takes a solo int. All its constructors that take an int also require a second argument that I would imagine Hibernate was not passing. Would this be the cause of the error?

What still bothers me is why BigInteger never appeared in the stack trace or the exception message. What does EOFException have to do with this problem??? Can anyone enlighten me on this?

Thanks,
Lee

_________________
http://www.URLinOne.com
http://www.AuctionRelay.com
http://www.OptionInsight.com


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.