-->
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.  [ 7 posts ] 
Author Message
 Post subject: Error net.sf.hibernate.tool.hbm2ddl.SchemaUpdate
PostPosted: Tue Mar 30, 2004 8:54 pm 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
I am using Hibernate 2.1.1 with JDK 1.4.2, Resin 2.1.12 and SAPDB 7.4.

Let me start off by saying that I am not doing a SchemaUpdate anywhere in my code. Yet I am getting the following error in my log file.
    ERROR net.sf.hibernate.tool.hbm2ddl.SchemaUpdate - Unsuccessful: alter table FREIGHTS foreign key FKD335B5907D7B26E0 (UPDATEBY) references USERS
    ERROR net.sf.hibernate.tool.hbm2ddl.SchemaUpdate - [-8006] (at 54): Data types must be compatible

I don't know if this is related or not but I am also getting java.lang.OutOfMemoryException even though I explicitly close all my sessions in a finally after the try-catch loop. Additionally, I turned the hibernate.cglib.use_reflection_optimizer to false in my hibernate.cfg.xml file (given below).

Here are my questions.

1. Is there any situation where SchemaUpdate would be executed by calling any of the methods I have specified below?
2. Is there any apparent reason for the java.lang.OutOfMemoryException based on my HibernateManager object (code given below)?

These questions do seem cryptic to me as well because I don't know what other information I can provide that may enable anyone to help me out.




The only methods that I call on my net.sf.hibernate.Session object are
    load() to get an instance of an object by the Id value
    createCriteria() to setup conditions to query results
    beginTransaction() to create a transaction before doing a saveOrUpdate()
    saveOrUpdate() to perform data update functions
    flush() to flush persistent objects before committing the transaction


The HibernateManager object is as follows

Code:
package com.foo.bar.utilities;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import org.apache.log4j.Logger;

/**
*  Description of the Class
*
* @author     gpani
* @version    1.1
* @since       JDK 1.4.2
*/
public class HibernateManager
{

  /**  The ThreadLocal for the HibernateManager */
  public final static ThreadLocal sessionThread = new ThreadLocal();

  /**  The SessionFactory for the HibernateManager */
  private final static SessionFactory sessionFactorySAP;

  /**
   *  This is the logger used by Log4J based on the setup in <i>log4j.properties
   *  </i>
   */
  private static Logger logger = Logger.getLogger(HibernateManager.class.getName());

  /**
   *  The value
   *
   * @exception  HibernateException  Description of the Exception
   */
  public static void closeSession()
    throws HibernateException
  {
    Session session = (Session) sessionThread.get();
    sessionThread.set(null);
    if (session != null)
    {
      session.close();
    }
  }

  /**
   *  The value
   *
   * @return                         Description of the Return Value
   * @exception  HibernateException  Description of the Exception
   */
  public static Session currentSession()
    throws HibernateException
  {
    Session session = (Session) sessionThread.get();
    /**  Open a new Session, if this Thread has none yet */
    if (session == null)
    {
      session = sessionFactorySAP.openSession();
      sessionThread.set(session);
    }
    return session;
  }

  static
  {
    try
    {
      /**
       *  File name need not be specified here. By default hibernate.cfg.xml is chosen.
       *  However, if the file name is changed in the application, it will need to
       *  be modified here
       */
      sessionFactorySAP = new Configuration().configure("/hibernate.cfg.xml").buildSessionFactory();
      logger.debug("Successfully created sessionFactory for SAPDB");
    }
    catch (HibernateException e)
    {
      logger.debug("HibernateException building SessionFactory: " + e.getMessage());
      throw new RuntimeException("HibernateException building SessionFactory: " + e.getMessage(), e);
    }
  }
}


The structure that I follow in my code to do any Hibernate functions is as follows:

Code:
public boolean save(Freight freight)
  {
    String sMethodName = "save(" + freight + "): ";
    Session hibernateSession = null;
    Transaction transaction = null;
    boolean saved = false;

    try
    {
      if (freight != null)
      {
        hibernateSession = HibernateManager.currentSession();
        transaction = hibernateSession.beginTransaction();
        hibernateSession.saveOrUpdate(freight);
        hibernateSession.flush();
        transaction.commit();
        saved = true;
      }
    }
    catch (HibernateException e)
    {
      try
      {
        transaction.rollback();
      }
      catch (Exception ex)
      {
        logger.warn("Exception encountered rolling back transaction due to HibernateException in " + sMethodName + Utilities.getStackTrace(ex));
      }

      logger.warn("Hibernate Exception in " + sMethodName + Utilities.getStackTrace(e));
    }
    catch (Exception e)
    {
      try
      {
        transaction.rollback();
      }
      catch (Exception ex)
      {
        logger.warn("Exception encountered rolling back transaction due to General Exception in " + sMethodName + Utilities.getStackTrace(ex));
      }
      logger.warn("General Exception in " + sMethodName + Utilities.getStackTrace(e));
    }
    finally
    {
      if (hibernateSession != null)
      {
        try
        {
          hibernateSession.close();
        }
        catch (HibernateException e)
        {
          logger.warn("Hibernate Exception closing session in " + sMethodName + Utilities.getStackTrace(e));
        }
      }

      try
      {
        HibernateManager.closeSession();
      }
      catch (HibernateException e)
      {
        logger.warn("Hibernate Exception closing HibernateManager in " + sMethodName + Utilities.getStackTrace(e));
      }
    }
    return saved;
  }




Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd" [
    <!ENTITY fileList SYSTEM "file:hbnfiles.xml">
]>

<hibernate-configuration>

  <!-- a SessionFactory instance listed as /jndi/name -->
  <session-factory>
    <property name="hibernate.connection.datasource">java:comp/env/hibernate/sapdb</property>
    <property name="dialect">net.sf.hibernate.dialect.SAPDBDialect</property>
    <property name="show_sql">true</property>
    <property name="transaction.factory_class">net.sf.hibernate.transaction.JDBCTransactionFactory</property>
    <property name="hibernate.cache.provider_class">net.sf.hibernate.cache.HashtableCacheProvider</property>
    <property name="hibernate.hbm2ddl.auto">update</property>
    <property name="hibernate.cglib.use_reflection_optimizer"> false</property>

    <!-- mapping files -->
    <!--&fileList;-->
   
    <!-- site mappings -->
    <mapping resource="com/foo/bar/beans/site/Freight.hbm.xml"/>
   
    <!-- site access mappings -->
    <mapping resource="com/foo/bar/beans/site/access/UserGroup.hbm.xml"/>
   
    <!-- user mappings -->
    <mapping resource="com/foo/bar/beans/user/User.hbm.xml"/>
   
  </session-factory>

</hibernate-configuration>


Top
 Profile  
 
 Post subject: additional logging
PostPosted: Tue Mar 30, 2004 9:19 pm 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
I changed the logging level to INFO and have the following trace.


Code:
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.Environment  - Hibernate 2.1.2
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.Environment  - hibernate.properties not found
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.Environment  - using CGLIB reflection optimizer
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.Configuration  - configuring from resource: /hibernate.cfg.xml
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.Configuration  - Configuration resource: /hibernate.cfg.xml
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.Configuration  - Mapping resource: com/bar/foo/beans/site/Freight.hbm.xml
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.Binder  - Mapping class: com.brightpoint.alltel.beans.site.Freight -> FREIGHTS
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.Configuration  - Mapping resource: com/bar/foo/beans/user/User.hbm.xml
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.Binder  - Mapping class: com.brightpoint.alltel.beans.user.User -> USERS
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.Configuration  - Configured SessionFactory: null
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.Configuration  - processing one-to-many association mappings
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.Configuration  - processing one-to-one association property references
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.Configuration  - processing foreign key constraints
[tcpConnection-6802-0] INFO  net.sf.hibernate.dialect.Dialect  - Using dialect: net.sf.hibernate.dialect.SAPDBDialect
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.SettingsFactory  - Use outer join fetching: true
[tcpConnection-6802-0] INFO  net.sf.hibernate.util.NamingHelper  - JNDI InitialContext properties:{}
[tcpConnection-6802-0] INFO  net.sf.hibernate.connection.DatasourceConnectionProvider  - Using datasource: java:comp/env/hibernate/sapdb
[tcpConnection-6802-0] INFO  net.sf.hibernate.transaction.TransactionFactoryFactory  - Transaction strategy: net.sf.hibernate.transaction.JDBCTransactionFactory
[tcpConnection-6802-0] INFO  net.sf.hibernate.transaction.TransactionManagerLookupFactory  - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.SettingsFactory  - Use scrollable result sets: true
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.SettingsFactory  - Use JDBC3 getGeneratedKeys(): false
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.SettingsFactory  - Optimize cache for minimal puts: false
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.SettingsFactory  - echoing all SQL to stdout
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.SettingsFactory  - Query language substitutions: {}
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.SettingsFactory  - cache provider: net.sf.hibernate.cache.HashtableCacheProvider
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.Configuration  - instantiating and configuring caches
[tcpConnection-6802-0] INFO  net.sf.hibernate.impl.SessionFactoryImpl  - building session factory
[tcpConnection-6802-0] INFO  net.sf.hibernate.impl.SessionFactoryObjectFactory  - no JNDI name configured
[tcpConnection-6802-0] INFO  net.sf.hibernate.dialect.Dialect  - Using dialect: net.sf.hibernate.dialect.SAPDBDialect
[tcpConnection-6802-0] INFO  net.sf.hibernate.util.NamingHelper  - JNDI InitialContext properties:{}
[tcpConnection-6802-0] INFO  net.sf.hibernate.connection.DatasourceConnectionProvider  - Using datasource: java:comp/env/hibernate/sapdb
[tcpConnection-6802-0] INFO  net.sf.hibernate.tool.hbm2ddl.SchemaUpdate  - Running hbm2ddl schema update
[tcpConnection-6802-0] INFO  net.sf.hibernate.tool.hbm2ddl.SchemaUpdate  - fetching database metadata
[tcpConnection-6802-0] INFO  net.sf.hibernate.tool.hbm2ddl.SchemaUpdate  - updating schema
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.Configuration  - processing one-to-many association mappings
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.Configuration  - processing one-to-one association property references
[tcpConnection-6802-0] INFO  net.sf.hibernate.cfg.Configuration  - processing foreign key constraints
[tcpConnection-6802-0] ERROR net.sf.hibernate.tool.hbm2ddl.SchemaUpdate  - Unsuccessful: alter table FREIGHTS foreign key FKD335B5907D7B26E0 (UPDATEBY) references USERS
[tcpConnection-6802-0] ERROR net.sf.hibernate.tool.hbm2ddl.SchemaUpdate  - [-8006] (at 54): Data types must be compatible
[tcpConnection-6802-0] ERROR net.sf.hibernate.tool.hbm2ddl.SchemaUpdate  - Unsuccessful: alter table FREIGHTS foreign key FKD335B5909B274E53 (CREATEBY) references USERS
[tcpConnection-6802-0] ERROR net.sf.hibernate.tool.hbm2ddl.SchemaUpdate  - [-8006] (at 54): Data types must be compatible
[tcpConnection-6802-0] INFO  net.sf.hibernate.tool.hbm2ddl.SchemaUpdate  - schema update complete


Top
 Profile  
 
 Post subject: Re: Error net.sf.hibernate.tool.hbm2ddl.SchemaUpdate
PostPosted: Tue Mar 30, 2004 10:03 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
gpani wrote:
Let me start off by saying that I am not doing a SchemaUpdate anywhere in my code.

Yes, you are.

Code:
<hibernate-configuration>
...
    <property name="hibernate.hbm2ddl.auto">update</property>
...
</hibernate-configuration>


That's your problem.

Cheers!
Rob


Top
 Profile  
 
 Post subject: Re: Error net.sf.hibernate.tool.hbm2ddl.SchemaUpdate
PostPosted: Wed Mar 31, 2004 12:07 am 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
RobJellinghaus wrote:
gpani wrote:
Let me start off by saying that I am not doing a SchemaUpdate anywhere in my code.

Yes, you are.

Code:
<hibernate-configuration>
...
    <property name="hibernate.hbm2ddl.auto">update</property>
...
</hibernate-configuration>


That's your problem.

Cheers!
Rob


Wow, I suck. Thanks so much. Now I have to go back to work and redeem myself.

Another stupid question before I get flamed like I deserve. Is that something that would cause a memory leak?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 4:17 am 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
No, I wouldn't think that alone would cause a memory leak. I don't know offhand what that might be about.

Cheers!
Rob


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 2:39 pm 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
RobJellinghaus wrote:
No, I wouldn't think that alone would cause a memory leak. I don't know offhand what that might be about.

Cheers!
Rob


Just a followup to anyone else that encounters this problem. It appears that Rob's suggestion cleared out the issue with my memory leak as well. I didn't change anything else in my code and performance is back to normal.


Top
 Profile  
 
 Post subject: Re: Error net.sf.hibernate.tool.hbm2ddl.SchemaUpdate
PostPosted: Wed Mar 31, 2004 3:25 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
gpani wrote:
Wow, I suck. Thanks so much. Now I have to go back to work and redeem myself.

I can relate.

http://forum.hibernate.org/viewtopic.php?p=2189874#2189874

:-)
Cheers!
Rob


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