-->
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.  [ 2 posts ] 
Author Message
 Post subject: Error in Session Factory creation
PostPosted: Wed Dec 07, 2005 1:01 pm 
Newbie

Joined: Wed Apr 06, 2005 1:37 am
Posts: 2
Location: Bangalore India
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0

Mapping documents:

Code between sessionFactory.openSession() and session.close():
Code:

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

/**
* Utility class containing basic code to
* create/get/close hibernate session
*/
public class HibernateUtil {
    /*class reference*/
    private static final Class CLASS=HibernateUtil.class;

    private static final SessionFactory sessionFactory;

    private static final String HIBERNATE_CONFIG_FILE_NAME="hibernate.cfg.xml";

    static {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            sessionFactory = new Configuration().configure(HIBERNATE_CONFIG_FILE_NAME).buildSessionFactory();
        } catch (Throwable ex) {
            DataAccessLogger.error("Initial SessionFactory creation failed.",ex,CLASS);
            throw new ExceptionInInitializerError(ex);
        }
    }

    /**
     * returns current hibernate session
     * @return Session
     * @throws DBDataAccessFailureException
     */
    public static Session currentSession() throws DBDataAccessFailureException {
        return SessionFactoryUtils.getSession(sessionFactory, true);
    }

    /**
     * closes hibernate session
     * @throws DBDataAccessFailureException
     */
    public static void closeSession() throws DBDataAccessFailureException {
        SessionFactoryUtils.releaseSession(sessionFactory);

    }

    /**
     * This is a simple method to reduce the amount of code that needs
     * to be written every time hibernate is used.
     */
    public static void rollback(Transaction tx) throws DBDataAccessFailureException {
        try {
            if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack()) {
                DataAccessLogger.debug("Tyring to rollback database transaction of this thread.",CLASS);
                tx.rollback();
            }
        } catch (HibernateException e) {
            /*Probably don't need to do anything - this is likely being
            called because of another exception, and we don't want to
            mask it with yet another exception.*/
            DataAccessLogger.error("failed to rollback transaction", e,CLASS);
        } finally {
            closeSession();
        }
    }
}




Code:
//************************************************************************
//
//   LocaleCache.java
//
//************************************************************************

//************************************************************************
//   Package
//************************************************************************

package com.hcomemea.common.locale;

//************************************************************************
//Imports
//************************************************************************

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;

import org.hibernate.Session;

import com.hcomemea.common.constants.ApplicationConstants;
import com.hcomemea.common.util.log.CommonLogger;
import com.hcomemea.common.cache.CacheException;
import com.hcomemea.common.cache.Cacheable;
import com.hcomemea.dataaccess.database.DBDataAccessFailureException;
import com.hcomemea.dataaccess.database.util.HibernateUtil;
import com.hcomemea.common.locale.data.LocaleData;
import com.hcomemea.common.locale.data.LocaleRule;
import com.hcomemea.common.locale.data.Rule;

/*
Singleton class
*/

/**
* This is the Locale object cache class. This is responsible for loading all
* the Loacle objects from the database and storing it in a localeList HashMap.
*/

public class LocaleCache implements Cacheable {

   private static final Class CLASS=LocaleCache.class;

   /**
    * LocaleCache instance object. LocaleCache is a singleton class. So
    * only one instance of it will be created.
    */
   private static LocaleCache hComLocaleCache = null;

   /**
    * HashMap object which stores all the Locale objects.
    */
   public static HashMap localeList = new HashMap();

   /**
    * Contructor for LocaleCache class. The contructor is protected so that
    * it cannot be instantiated by classes outside the package.
    */
   protected LocaleCache() {
      // Exists only to defeat instantiation.
   }

   /**
    * Since the class is a singleton class, this method is responsible for
    * making sure that only one instance exists.
    *
    * @return: LocaleCache instance.
    */
   public static LocaleCache getInstance() {
      if (hComLocaleCache == null) {
         hComLocaleCache = new LocaleCache();
      }
      return hComLocaleCache;
   }

   /**
    * Loads all the Locale objects from the database and stores it in a
    * HashMap.
    */
   public HashMap load() throws CacheException {
      Session session = null;
      try {
         session = HibernateUtil.currentSession();
         Iterator iterator = session.createQuery(
               "from com.hcomemea.common.locale.data.LocaleData").list()
               .iterator();
         
         while (iterator.hasNext()) {
            Object row = iterator.next();
            LocaleData hcomLocale = (LocaleData) row;
            Integer localeId = hcomLocale.getLocaleId();
            HashMap rulesList = getRulesList(hcomLocale);
            hcomLocale.setRules(rulesList);
            hcomLocale.setCid(ApplicationConstants.IAN_CUSTOMER_ID);
            localeList.put(localeId, hcomLocale);
         }
      } catch (DBDataAccessFailureException ex) {
         CommonLogger.error("DBDataAccessFailureException in LocaleCache"+ex.getMessage(),ex,CLASS);
         throw new CacheException(ex);
      } finally {
         try {
            HibernateUtil.closeSession();
         } catch (DBDataAccessFailureException ex) {
            CommonLogger.error("DBDataAccessFailureException in LocaleCache"+ex.getMessage(),ex,CLASS);
            throw new CacheException(ex);
         }
      }
      return localeList;
   }

   /**
    * This method refreshes the localeList HashMap by reloading it from the
    * database.
    */
   public void refresh() throws CacheException {
      localeList = load();
   }

   /**
    * This method loads Rules list HashMap corresponding to a Locale object.
    *
    * @param hcomLocale:
    *            LocaleData object for which ruleslist is to be built
    * @return: Rules List hashMap for the locale object.
    */
   private HashMap getRulesList(LocaleData hcomLocale) throws CacheException{
      HashMap rulesListForALocale = new HashMap();

      Collection rulesList = hcomLocale.getRulesList();
      Iterator it = rulesList.iterator();

      while (it.hasNext()) {
         LocaleRule hcomLocaleRule = (LocaleRule) it.next();
         String ruleValue = hcomLocaleRule.getRuleValue();
         Rule hcomRule = hcomLocaleRule.getRule();
         String ruleDescription = hcomRule.getRuleDescription();
         rulesListForALocale.put(ruleDescription, ruleValue);
      }
      return rulesListForALocale;
   }

   /**
    * Method takes a LocaleId for the Locale and returns the corresponding
    * Locale object by looking in the localeList HashMap.
    *
    * @param LocaleId:
    *            LocaleId of the Locale object.
    * @return: Corresponding Locale object.
    */
   public LocaleData getLocale(Integer LocaleId) {
      return (LocaleData) localeList.get(LocaleId);
   }
}



Code:

//************************************************************************
//
//   LocaleData.java
//
//************************************************************************

//************************************************************************
//   Package
//************************************************************************

package com.hcomemea.common.locale.data;

//************************************************************************
//Imports
//************************************************************************

import java.util.Collection;
import java.util.HashMap;
import java.io.Serializable;

//************************************************************************
//Classes
//************************************************************************

/**
* An object that represents a Locale Object. Each Locale object is uniquely
* identified by a Country and Language object. Each Locale object has its own
* value for Language, Country, LocaleCode, Default Language, Time Format, Date
* Format, UomDistance, UomFormat and Phone format.
*
*/
public class LocaleData implements Serializable {
   // ************************************************************************
   // Class Data Members for LocaleData
   // ************************************************************************

   /**
    * Identifier that uniquely identifies a Locale Object.
    */

   private Integer localeId;

   public Integer getLocaleId() {
      return this.localeId;
   }

   public void setLocaleId(Integer localeId) {
      this.localeId = localeId;
   }

   /**
    * Locale Code for a Locale.
    */
   private String localeCode;

   public String getLocaleCode() {
      return this.localeCode;
   }

   public void setLocaleCode(String localeCode) {
      this.localeCode = localeCode;
   }

   /**
    * Default Language for a Locale.
    */
   private String defaultLanguage;

   public String getDefaultLanguage() {
      return this.defaultLanguage;
   }

   public void setDefaultLanguage(String defaultLanguage) {
      this.defaultLanguage = defaultLanguage;
   }
   /**
    * Default URL for a Locale.
    */
   
      
   private String isdefaultURL;

   public String getIsdefaultURL() {
      return this.isdefaultURL;
   }
   
   public void setIsdefaultURL(String isdefaultURL) {
      this.isdefaultURL = isdefaultURL;
   }

   /**
    * Collection of Locale rules object for a Locale object.
    */
   private Collection rulesList = null;

   public Collection getRulesList() {
      return this.rulesList;
   }

   public void setRulesList(Collection rulesList) {
      this.rulesList = rulesList;
   }

   /**
    * A hash map consisiting of a ruleDescription and a ruleValue 
    * for a Locale object.
    */
   private HashMap rules = new HashMap();

   public HashMap getRules() {
      return this.rules;
   }

   public void setRules(HashMap rules) {
      this.rules = rules;
   }

   /**
    * Date format for the Locale object.
    */
   private String dateFormat;

   public String getDateFormat() {
      return this.dateFormat;
   }

   public void setDateFormat(String dateFormat) {
      this.dateFormat = dateFormat;
   }

   /**
    * Time Format for a Locale.
    */
   private String timeFormat;

   public String getTimeFormat() {
      return this.timeFormat;
   }

   public void setTimeFormat(String timeFormat) {
      this.timeFormat = timeFormat;
   }

   /**
    * Unit of Measurement of distance for a Locale Object.
    */
   private String uomDistance;

   public String getUomDistance() {
      return this.uomDistance;
   }

   public void setUomDistance(String uomDistance) {
      this.uomDistance = uomDistance;
   }

   /**
    * Unit of Measurement Format for a Locale Object.
    */
   private String uomFormat;

   public String getUomFormat() {
      return this.uomFormat;
   }

   public void setUomFormat(String uomFormat) {
      this.uomFormat = uomFormat;
   }

   /**
    * Phone format for a Locale object.
    */
   private String phoneFormat;

   public String getPhoneFormat() {
      return this.phoneFormat;
   }

   public void setPhoneFormat(String phoneFormat) {
      this.phoneFormat = phoneFormat;
   }

   /**
    * URL for a Locale object. Each Locale object has its corresponding URL.
    */
   private String url;

   public String getUrl() {
      return this.url;
   }

   public void setUrl(String url) {
      this.url = url;
   }

   /**
    * Each Locale object is identified by a Country object and Language object.
    * This attribute stores the Reference to Country object.
    */
   private Country country;

   public Country getCountry() {
      return this.country;
   }

   public void setCountry(Country country) {
      this.country = country;
   }

   /**
    * Each Locale object is identified by a Country object and Language object.
    * This attribute stores the Reference to Language object.
    */
   private Language language;

   public Language getLanguage() {
      return this.language;
   }

   public void setLanguage(Language language) {
      this.language = language;
   }

   /**
    *
    */
   private long cid;

   public long getCid() {
      return this.cid;
   }

   public void setCid(long cid) {
      this.cid = cid;
   }

   /**
    * Returns true if the argument is an LocaleData instance and all
    * identifiers for this entity equal the identifiers of the argument entity.
    * Returns false otherwise.
    */
   public boolean equals(Object object) {
      if (this == object) {
         return true;
      }
      if (!(object instanceof LocaleData)) {
         return false;
      }
      final LocaleData that = (LocaleData) object;
      if (this.localeId == null || that.localeId == null
            || !this.localeId.equals(that.localeId)) {
         return false;
      }
      return true;
   }

   /**
    * Returns a hash code based on this entity's identifiers.
    */
   public int hashCode() {
      int hashCode = 0;
      hashCode = 29 * hashCode + (localeId == null ? 0 : localeId.hashCode());

      return hashCode;
   }

} // end of class









Full stack trace of any exception that occurs:


Name and version of the database you are using:
SQL Server 2K



The generated SQL (show_sql=true): The exception was thrown before the SQL was generated.




Debug level Hibernate log excerpt:
ERROR - [com.hcomemea.dataaccess.database.util.HibernateUtil][Initial SessionFactory creation failed.]
java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit(ILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V
at net.sf.cglib.core.ClassEmitter.begin_class(ClassEmitter.java:63)
at net.sf.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:173)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:215)
at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:117)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
at org.hibernate.impl.SessionFactoryImpl.<clinit>(SessionFactoryImpl.java:321)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1005)
at com.hcomemea.dataaccess.database.util.HibernateUtil.<clinit>(HibernateUtil.java:27)
at com.hcomemea.common.locale.LocaleCache.load(LocaleCache.java:86)
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:585)
at com.hcomemea.common.cache.CacheManager.loadOnStartUp(CacheManager.java:116)
at com.hcomemea.common.servlet.StartUpServlet.init(StartUpServlet.java:52)
at com.caucho.server.http.Application.createServlet(Application.java:3114)
at com.caucho.server.http.Application.loadServlet(Application.java:3065)
at com.caucho.server.http.Application.initServlets(Application.java:1923)
at com.caucho.server.http.Application.init(Application.java:1849)
at com.caucho.server.http.VirtualHost.initWars(VirtualHost.java:837)
at com.caucho.server.http.VirtualHost.init(VirtualHost.java:695)
at com.caucho.server.http.ServletServer.initHosts(ServletServer.java:887)
at com.caucho.server.http.ServletServer.initInternal(ServletServer.java:729)
at com.caucho.server.http.ServletServer.init(ServletServer.java:538)
at com.caucho.server.http.ResinServer.init(ResinServer.java:415)
at com.caucho.server.http.ResinServer.main(ResinServer.java:1176)
at com.caucho.server.http.HttpServer.main(HttpServer.java:103)



Quote:
What we have already checked:
1) The same .war is running successfully on other machines. We have compared the classpath (which is identical)
2) We have verified that the org.objectweb.asm.ClassVisitor class is getting loaded from the same jar (asm.jar) as compared to other machines (where the code is working)

3) The DB Connectivity is available
4) hibernate.cfg.xml is identical to other machines where it is working
5) Switched on the TRACE level debug on and the output is identical (in terms of loading the hibernate mappings) till the point where the session is instantiated. At this point the machine on which hibernate is not working bombs with the above exception.

We are using Resin 2.1.6 with Hibernate 3.0 connecting to SQL Server 2K thorugh Microsoft SQL Server 2000 JDBC Driver running on Redhat Linux Enterprise edition 4.0 AS. JDK version is 1.5



Any pointers to the potential cause or the probable solution would be highly appreciated.
Regards



_________________
Rishi K Srivastava
Senior Associate (Technology)
Sapient


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 1:17 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
there is a jar in your classpath that is not the correct version. you want to make sure you are using the jars that are distributed *with* hibernate ( see the readme file ).


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