-->
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: Building SessionFactories failed under JBoss
PostPosted: Thu Jun 01, 2006 6:32 pm 
Newbie

Joined: Sun Sep 11, 2005 7:46 pm
Posts: 15
Dear folks,

I was trying to display data on a jsp page. But the building of SessionFactories was always failed. My application needs to access two different database as three different roles. So there are three hibernate configuration files. It seems that the JBoss did find the datasource because the mappings were partially done when the SessionFactories failed to be built.

Hibernate version: 3.2 CR 2

JBoss app. server version: 4.0.4 CR 2

Mapping documents:
All the mappings are correct (Tested without any app server, using mere JDBC). Here is one of my three hibernate configuration files. The other two are very similar.


Code:
<hibernate-configuration>

   <!-- Die Konfiguration der SessionFactory fuer die Umfrage DB -->
   <session-factory name="java:/hibernate/UmfrageSessionFactory">

      <!-- Der JNDI Name der datasource für die Umfragen DB ist
         der maxdb-umfrage-ds.xml von JBoss zu entnehmen -->

      <property name="hibernate.connection.datasource">
         java:UMFRAGEDS
      </property>

      <!-- SQL Dialekt  -->
      <property name="hibernate.dialect">
         org.hibernate.dialect.SAPDBDialect
      </property>

      <property name="max_fetch_depth">3</property>



      <!-- Echo all executed SQL to stdout -->
      <property name="show_sql">true</property>
      <property name="format_sql">true</property>
      <property name="hibernate.use_sql_comments">true</property>


      <!-- JBoss TransactionManager Factory Klasse -->
      <property name="hibernate.transaction.factory_class">
         org.hibernate.transaction.CMTTransactionFactory
      </property>

      <property
         name="hibernate.transaction.flush_before_completion">
         true
      </property>
      <property name="hibernate.transaction.auto_close_session">
         true
      </property>

      <!-- JBoss TransactionManager Lookup Klasse -->
      <property name="hibernate.transaction.manager_lookup_class">
         org.hibernate.transaction.JBossTransactionManagerLookup
      </property>

      <property name="hibernate.connection.release_mode">
         auto
      </property>


      <!-- Die Pfade zu den Mapping Dateien -->
      <mapping resource="..." />
                   ...

   </session-factory>

</hibernate-configuration>





UmfrageDAO.java

Code:
public class UmfrageDAO extends GenericUmfrageDAO<Umfrage, Integer> {

   protected UmfrageDAO() {
      super(Umfrage.class);
   }

   public UmfrageDAO(Session session) {
      super(Umfrage.class, session);
   }

   @Override
   protected void setSession(Session s) {
      session = s;
   }
}


HibernateUtil.java

Code:
public class HibernateUtil {
   
   public static final HibernateUtil INSTANCE = new HibernateUtil();

   private static final String HIBERNATE_UMFRAGE_CFG = "hibernate_umfrage.cfg.xml";

   private static final String HIBERNATE_PERSONAL_CFG = "hibernate_personal.cfg.xml";

   private static final String HIBERNATE_STUDINFO_CFG = "hibernate_studinfo.cfg.xml";

   private static SessionFactory umfrageSessionFactory;

   private static SessionFactory personalSessionFactory;

   private static SessionFactory studinfoSessionFactory;

   static {
      try {
         umfrageSessionFactory = new Configuration().configure(
               HIBERNATE_UMFRAGE_CFG).buildSessionFactory();
         
         personalSessionFactory = new Configuration().configure(
               HIBERNATE_PERSONAL_CFG).buildSessionFactory();
         
         studinfoSessionFactory = new Configuration().configure(
               HIBERNATE_STUDINFO_CFG).buildSessionFactory();

      } catch (Throwable ex) {
         log.error("Building SessionFactories failed.", ex);
         throw new ExceptionInInitializerError(ex);
      }
   }
   
   public static SessionFactory getUmfrageSessionFactory(){
      return umfrageSessionFactory;
   }
   
   public static SessionFactory getPersonalSessionFactory(){
      return personalSessionFactory;
   }
   
   public static SessionFactory getStudinfoSessionFactory(){
      return studinfoSessionFactory;
   }
   
   public static Session getUmfrageSession() throws InfrastructureException {
      log.info("entering getUmfrageSession()");
      try {
         Session session = umfrageSessionFactory.getCurrentSession();
         log.info("leaving getUmfrageSession()");
         return session;
      } catch (HibernateException he) {
         log.error("Retrieving current Umfrage session failed.", he);
         throw new InfrastructureException(he);
      }
   }

   public static Session getPersonalSession() throws InfrastructureException {
      log.info("entering getPersonalSession()");
      try {
         Session session = personalSessionFactory.getCurrentSession();

         // wird bei read-only Sessions empfohlen, um die Performanz zu
         // verbessern
         // (siehe Hibernate 3 API Doc)
         session.setFlushMode(FlushMode.NEVER);

         log.info("leaving getPersonalSession()");
         return session;
      } catch (HibernateException he) {
         log.error("Retrieving current Personal session failed.", he);
         throw new InfrastructureException(he);
      }
   }

   public static Session getStudinfoSession() throws InfrastructureException {
      log.info("entering getStudinfoSession()");
      try {
         Session session = studinfoSessionFactory.getCurrentSession();

         // wird bei read-only Sessions empfohlen, um die Performanz zu
         // verbessern
         // (siehe Hibernate 3 API Doc)
         session.setFlushMode(FlushMode.NEVER);

         log.info("leaving getStudinfoSession()");
         return session;
      } catch (HibernateException he) {
         log.error("Retrieving current Studinfo session failed.", he);
         throw new InfrastructureException(he);
      }
   }

}


UmfrageDAOFactory.java
Code:
public class UmfrageDAOFactory {
   public static final UmfrageDAOFactory INSTANCE = new UmfrageDAOFactory();

   public DurchfuehrungDAO getDurchfuehrungDAO() {
      return new DurchfuehrungDAO(getCurrentSession());
   }

   public UmfrageDAO getUmfrageDAO() {
      return new UmfrageDAO(getCurrentSession());
   }

        ...

   protected Session getCurrentSession() {
      return HibernateUtil.getUmfrageSessionFactory().getCurrentSession();
   }

   private UmfrageDAOFactory() {
   }
}


UmfrageTableData.java
this is an extremely rudimentary class for testing the JSF UI.

Code:
public class UmfrageTableData {

   private static UmfrageDAO uDAO = UmfrageDAOFactory.INSTANCE.getUmfrageDAO();
   
   private static final List<Umfrage> umfragen = uDAO.findAll();
   
   public List<Umfrage> getAllUmfragen() {
      return umfragen;
   }
}


index.jsp
Code:
<html>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<f:view>
   <body>
   <h:form>
      <h:dataTable value="#{umfrageTableData.umfragen}" var="umfrage">
         <h:column>
            <h:outputText value="#{umfrage.id}" />
            <f:verbatim>,</f:verbatim>
         </h:column>

         <h:column>
            <h:outputText value="#{umfrage.umfrTyp}" />
         </h:column>
      </h:dataTable>
   </h:form>
   </body>
</f:view>
</html>




Full stack trace of any exception that occurs:

00:24:05,181 INFO [SessionFactoryImpl] building session factory
00:24:05,211 WARN [ConfigurationFactory] No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/E:/Programme/jboss-4.0.4.CR2/server/default/tmp/deploy/tmp27542umfrage-exp.war/WEB-INF/lib/ehcache-1.2.jar!/ehcache-failsafe.xml
00:24:07,244 INFO [SessionFactoryObjectFactory] Factory name: java:/hibernate/UmfrageSessionFactory
00:24:07,244 INFO [NamingHelper] JNDI InitialContext properties:{}
00:24:07,244 INFO [NamingHelper] Creating subcontext: hibernate
00:24:07,244 INFO [SessionFactoryObjectFactory] Bound factory to JNDI name: java:/hibernate/UmfrageSessionFactory
00:24:07,244 WARN [SessionFactoryObjectFactory] InitialContext did not implement EventContext
00:24:07,244 INFO [NamingHelper] JNDI InitialContext properties:{}
00:24:07,264 INFO [STDOUT] 00:24:07,254 ERROR [HibernateUtil] Building SessionFactories failed.
java.lang.ClassCastException: org.jboss.tm.TxManager
at org.hibernate.transaction.JNDITransactionManagerLookup.getTransactionManager(JNDITransactionManagerLookup.java:23)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:322)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1213)
at de.fhzw.portal.umfragesystem.model.utils.HibernateUtil.<clinit>(HibernateUtil.java:71)
at de.fhzw.portal.umfragesystem.model.dao.umfrage.UmfrageDAOFactory.getCurrentSession(UmfrageDAOFactory.java:43)
at de.fhzw.portal.umfragesystem.model.dao.umfrage.UmfrageDAOFactory.getUmfrageDAO(UmfrageDAOFactory.java:38)
at test.UmfrageTableData.<clinit>(UmfrageTableData.java:12)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
....


I've tracked to the source code in the Configuration.java. It went wrong in this method:
Code:
/**
    * Instantiate a new <tt>SessionFactory</tt>, using the properties and
    * mappings in this configuration. The <tt>SessionFactory</tt> will be
    * immutable, so changes made to the <tt>Configuration</tt> after
    * building the <tt>SessionFactory</tt> will not affect it.
    *
    * @return a new factory for <tt>Session</tt>s
    * @see org.hibernate.SessionFactory
    */
   public SessionFactory buildSessionFactory() throws HibernateException {
      log.debug( "Preparing to build session factory with filters : " + filterDefinitions );
      secondPassCompile();
      validate();
      Environment.verifyProperties( properties );
      Properties copy = new Properties();
      copy.putAll( properties );
      PropertiesHelper.resolvePlaceHolders( copy );
      Settings settings = buildSettings( copy );

      return new SessionFactoryImpl(
            this,
            mapping,
            settings,
            getInitializedEventListeners()
         );
   }


and the line 1213 is exactly here: return new SessionFactoryImpl....


Name and version of the database you are using:

SAP DB. I guess it's irrelevant here. Since all the DB stuff "an sich" were tested successfully under the JDBC version of the hibernate configuration

Debug level Hibernate log excerpt:

INFO I guess?


Any help/hint/enlightenment would be highly appreciated! It's 00:30 am now and I'm still debugging in my office....


Regards,
Ellen Zhao


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 02, 2006 5:29 am 
Newbie

Joined: Sun Sep 11, 2005 7:46 pm
Posts: 15
Any enlightenment please? I want to tell hibernate to use JBoss cache, how to do it in the hibernate configuration file? Thank you very much in advance!

Regards,
Ellen


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 02, 2006 7:25 am 
Regular
Regular

Joined: Thu Sep 22, 2005 1:53 pm
Posts: 88
Location: Rio de Janeiro
If you use it inside JBoss why don´t you use it as
a managed Service? You can create a hibernate-service.xml
in stead of hibernate.cfg.xml take a look at this part of teh hibernate
documentation:

JMX Deployment

_________________
Don´t forget to rate!


Top
 Profile  
 
 Post subject: thank you very much!
PostPosted: Wed Jun 07, 2006 12:20 pm 
Newbie

Joined: Sun Sep 11, 2005 7:46 pm
Posts: 15
Many thanks and I'll try it out right away!


Top
 Profile  
 
 Post subject: no luck....
PostPosted: Sat Jun 10, 2006 3:37 am 
Newbie

Joined: Sun Sep 11, 2005 7:46 pm
Posts: 15
Dear folks,

I tried the jmx service but it didn't work. The service failed to start. Same error message like I pasted above. The JBoss transaction manager was not found. But I did specify in the configuration file about which class to use as JBoss transaction manager....I guess the problem lies in the JBoss tuning....

Any help please? Thank you very much in advance!

The JBoss Server I installed was version 4.0.4 RC 2. Thanks again!


Regards,
Ellen


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.