title: GenericJDBCException: could not load an entity
body: <p>I am trying to read a lazy initialized entity <code>ProductUnits</code> which is a persistent set, and opened a new session for the same. </p>
  
  <pre><code>Session session = HibernateUtil.getSessionFactory().openSession();
  session.update(stock.getProduct());
  List&lt;ProductUnits&gt; units = new ArrayList&lt;ProductUnits&gt;(stock.getProduct().getUnits());
  </code></pre>
  
  <p>The problem is during the run time it throws the exception</p>
  
  <pre><code>org.hibernate.exception.GenericJDBCException: could not load an entity: [hibernate.tables.plain.Product#1]
  </code></pre>
  
  <p>but while doing a <strong>step by step debug it runs perfectly fine</strong>. Is it that the session.update takes some time or am I missing something</p>
  
  <p>the exception stack is</p>
  
  <pre><code>    Exception in thread "AWT-EventQueue-0" org.hibernate.exception.GenericJDBCException: could not load an entity: [hibernate.tables.plain.Product#2]
  at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
  at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
  at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
  at org.hibernate.loader.Loader.loadEntity(Loader.java:1895)
  at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:71)
  at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:65)
  at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3072)
  at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:434)
  at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:415)
  at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:165)
  at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:121)
  at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:905)
  at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:863)
  at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:95)
  at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:140)
  at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
  at hibernate.tables.plain.Product_$$_javassist_15.getUnits(Product_$$_javassist_15.java)
  at bill.mainBill.InputProductsPanel.computeStockAvailablity(InputProductsPanel.java:278)
  at bill.mainBill.InputProductsPanel.findStock(InputProductsPanel.java:242)
  at bill.mainBill.ProductDetailPanel.setStats(ProductDetailPanel.java:315)
  at bill.mainBill.ProductDetailPanel$3.focusLost(ProductDetailPanel.java:187)
  at java.awt.AWTEventMulticaster.focusLost(Unknown Source)
  at java.awt.Component.processFocusEvent(Unknown Source)
  at java.awt.Component.processEvent(Unknown Source)
  at java.awt.Container.processEvent(Unknown Source)
  at java.awt.Component.dispatchEventImpl(Unknown Source)
  at java.awt.Container.dispatchEventImpl(Unknown Source)
  at java.awt.Component.dispatchEvent(Unknown Source)
  at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
  at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
  at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
  at java.awt.Component.dispatchEventImpl(Unknown Source)
  at java.awt.Container.dispatchEventImpl(Unknown Source)
  at java.awt.Component.dispatchEvent(Unknown Source)
  at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
  at java.awt.EventQueue.access$000(Unknown Source)
  at java.awt.EventQueue$3.run(Unknown Source)
  at java.awt.EventQueue$3.run(Unknown Source)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
  at java.awt.EventQueue$4.run(Unknown Source)
  at java.awt.EventQueue$4.run(Unknown Source)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
  at java.awt.EventQueue.dispatchEvent(Unknown Source)
  at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
  at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
  at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
  at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  at java.awt.EventDispatchThread.run(Unknown Source)
  
  
      Caused by: java.sql.SQLException: Invalid value for getInt() - 'N'
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
  at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2727)
  at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2815)
  at org.hibernate.type.IntegerType.get(IntegerType.java:51)
  at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:184)
  at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:173)
  at org.hibernate.type.AbstractType.hydrate(AbstractType.java:105)
  at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2124)
  at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1404)
  at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1332)
  at org.hibernate.loader.Loader.getRow(Loader.java:1230)
  at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:603)
  at org.hibernate.loader.Loader.doQuery(Loader.java:724)
  at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
  at org.hibernate.loader.Loader.loadEntity(Loader.java:1881)
  ... 48 more
  </code></pre>
  
  <p>then mapping file is as follows</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                                     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt;
  &lt;!-- Generated Apr 3, 2012 1:21:15 PM by Hibernate Tools 3.4.0.CR1 --&gt;
  &lt;hibernate-mapping&gt;
   &lt;class name="hibernate.tables.plain.ProductUnits" table="PRODUCT_UNITS"&gt;
    &lt;composite-id mapped="false" unsaved-value="undefined"&gt;
     &lt;key-many-to-one class="hibernate.tables.plain.Product"
      column="Product_ID" name="product"/&gt;
     &lt;key-many-to-one class="hibernate.tables.plain.Unit" column="Unit_ID" name="unit"/&gt;
    &lt;/composite-id&gt;
    &lt;property generated="never" lazy="false" name="basePrice" type="java.lang.Double"&gt;
     &lt;column name="BASE_PRICE"/&gt;
    &lt;/property&gt;
   &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>and the product mapping</p>
  
  <pre><code> &lt;class name="hibernate.tables.plain.Product" table="PRODUCT"&gt;
          &lt;id name="id" type="java.lang.Long"&gt;
              &lt;column name="ID" /&gt;
              &lt;generator class="assigned" /&gt;
          &lt;/id&gt;
          &lt;property name="name" type="java.lang.String"&gt;
              &lt;column name="NAME" /&gt;
          &lt;/property&gt;
          &lt;property name="recommendedHolding" type="java.lang.Double"&gt;
              &lt;column name="RECOMMENDED_HOLDING" /&gt;
          &lt;/property&gt;
          &lt;set name="units" table="Product_Units" inverse="false" lazy="true"&gt;
              &lt;key&gt;
                  &lt;column name="Product_ID" /&gt;
              &lt;/key&gt;
              &lt;one-to-many  class="hibernate.tables.plain.ProductUnits" /&gt;
          &lt;/set&gt;
          &lt;property name="active" type="java.lang.Character"&gt;
              &lt;column name="ACTIVE" /&gt;
          &lt;/property&gt;
      &lt;/class&gt;
  </code></pre>