-->
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.  [ 6 posts ] 
Author Message
 Post subject: Problem intializing Hibernate Session
PostPosted: Sat Apr 02, 2005 6:02 pm 
Newbie

Joined: Tue Mar 22, 2005 10:31 pm
Posts: 8
I have been working with Hibernate for some time now and have not had a problem like this with trying to establish a session. I am working on a portal enviornment, deploying into exo. Everything was working fine and now something seems to have changed and I cannot seem to pinpoint it.

I even tried creating a new whole new project in eclipse and I still seem to get the issue.

The error I get is this:

[portletcontainer] [ERROR] exception while initializing portlet : JupiterPortal
null
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:805)
at com.echostorm.jupiter.hibernate.AppSession.initialization(AppSession.java:60)
at com.echostorm.jupiter.hibernate.AppSession.getSession(AppSession.java:33)
at com.echostorm.jupiter.Portal.init(Portal.java:50)
at org.exoplatform.services.portletcontainer.impl.PortletApplicationProxy.init(PortletApplicationProxy.java:87)
at org.exoplatform.services.portletcontainer.impl.PortletApplicationProxy.getPortlet(PortletApplicationProxy.java:62)
at org.exoplatform.services.portletcontainer.impl.PortletApplicationHandler.process(PortletApplicationHandler.java:211)
at org.exoplatform.services.portletcontainer.impl.servlet.ServletWrapper.service(ServletWrapper.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
[...................................]

----------------------------------

Here is part of my portal code and as you can see it tries to get the session in the init, which gets called when someone hits the portal.

private static Log logger = LogFactory.getLog(Portal.class);

Session hibernateSession = null;

public void init(PortletConfig pConfig) throws PortletException
{
super.init(pConfig);
hibernateSession = AppSession.getSession();
logger.info("init");
}


----------------------
Here is my AppSession, which I tried leaving out all my classes, I didn't add them to the config thinking one of them was causing the issue and still nothing.

/*
* Created on Mar 18, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.echostorm.jupiter.hibernate;

/** Various Hibernate-related imports */
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.tool.hbm2ddl.SchemaUpdate;

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

public class AppSession
{
private static Log logger = LogFactory.getLog(AppSession.class);

static String fileSep =
System.getProperty("file.separator");

/** We use this session factory to create our sessions */
public static SessionFactory sessionFactory;

public static Session getSession()
{

try
{
if (sessionFactory == null) initialization();
return sessionFactory.openSession();
} catch (Exception e)
{
logger.debug(e);
return null;
}
}

/**
* Loads the Hibernate configuration information, sets up the
* database and the Hibernate session factory.
*/
public static void initialization()
{
logger.info("Initialization");
try
{

Configuration myConfiguration = new Configuration();
// This is the code that updates the database to the
// current schema.
new SchemaUpdate(myConfiguration).execute(true, true);

// Sets up the session factory (used in the rest
// of the application).
logger.debug("About to build session");
sessionFactory = myConfiguration.buildSessionFactory();

} catch (Exception e)
{
logger.debug(e);
}
}

public static void main(String[] args)
{
initialization();
}


}
------------------------------------------------------

Here is my hibernate.properties file:

hibernate.connection.driver_class=org.hsqldb.jdbcDriver
#hibernate.connection.driver_class=com.p6spy.engine.spy.P6SpyDriver
hibernate.connection.url= jdbc:hsqldb:hsql://localhost:9001
hibernate.connection.username=sa
hibernate.connection.password=
hibernate.dialect=net.sf.hibernate.dialect.HSQLDialect
#hibernate.show_sql=true


-----

And here is my logging code that I get from hibernate.


===== Saturday, April 2, 2005 4:53:42 PM US/Eastern =====
2005-04-02 16:53:52,387 [http-8080-Processor21] INFO AppSession - Initialization
2005-04-02 16:53:52,387 [http-8080-Processor21] INFO AppSession - Initialization
2005-04-02 16:53:52,452 [http-8080-Processor21] INFO Environment - Hibernate 2.1.8
2005-04-02 16:53:52,466 [http-8080-Processor21] INFO Environment - loaded properties from resource hibernate.properties: {hibernate.connection.username=sa, hibernate.connection.password=, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=net.sf.hibernate.dialect.HSQLDialect, hibernate.connection.url=jdbc:hsqldb:hsql://localhost:9001, hibernate.connection.driver_class=org.hsqldb.jdbcDriver}
2005-04-02 16:53:52,469 [http-8080-Processor21] INFO Environment - using CGLIB reflection optimizer
2005-04-02 16:53:52,472 [http-8080-Processor21] INFO Environment - using JDK 1.4 java.sql.Timestamp handling
2005-04-02 16:53:52,594 [http-8080-Processor21] INFO Dialect - Using dialect: net.sf.hibernate.dialect.HSQLDialect
2005-04-02 16:53:52,768 [http-8080-Processor21] INFO DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
2005-04-02 16:53:52,768 [http-8080-Processor21] INFO DriverManagerConnectionProvider - Hibernate connection pool size: 20
2005-04-02 16:53:52,777 [http-8080-Processor21] INFO DriverManagerConnectionProvider - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:hsql://localhost:9001
2005-04-02 16:53:52,777 [http-8080-Processor21] INFO DriverManagerConnectionProvider - connection properties: {user=sa, password=}
2005-04-02 16:53:52,777 [http-8080-Processor21] INFO SchemaUpdate - Running hbm2ddl schema update
2005-04-02 16:53:52,777 [http-8080-Processor21] INFO SchemaUpdate - fetching database metadata
2005-04-02 16:53:53,242 [http-8080-Processor21] INFO SchemaUpdate - updating schema
2005-04-02 16:53:53,243 [http-8080-Processor21] INFO Configuration - processing one-to-many association mappings
2005-04-02 16:53:53,243 [http-8080-Processor21] INFO Configuration - processing one-to-one association property references
2005-04-02 16:53:53,243 [http-8080-Processor21] INFO Configuration - processing foreign key constraints
2005-04-02 16:53:53,247 [http-8080-Processor21] INFO SchemaUpdate - schema update complete
2005-04-02 16:53:53,252 [http-8080-Processor21] INFO DriverManagerConnectionProvider - cleaning up connection pool: jdbc:hsqldb:hsql://localhost:9001
2005-04-02 16:53:53,253 [http-8080-Processor21] DEBUG AppSession - About to build session
2005-04-02 16:53:53,253 [http-8080-Processor21] DEBUG AppSession - About to build session
2005-04-02 16:53:53,253 [http-8080-Processor21] INFO Configuration - processing one-to-many association mappings
2005-04-02 16:53:53,253 [http-8080-Processor21] INFO Configuration - processing one-to-one association property references
2005-04-02 16:53:53,253 [http-8080-Processor21] INFO Configuration - processing foreign key constraints
2005-04-02 16:53:53,271 [http-8080-Processor21] INFO Dialect - Using dialect: net.sf.hibernate.dialect.HSQLDialect
2005-04-02 16:53:53,297 [http-8080-Processor21] INFO SettingsFactory - Use outer join fetching: true
2005-04-02 16:53:53,297 [http-8080-Processor21] INFO DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
2005-04-02 16:53:53,297 [http-8080-Processor21] INFO DriverManagerConnectionProvider - Hibernate connection pool size: 20
2005-04-02 16:53:53,297 [http-8080-Processor21] INFO DriverManagerConnectionProvider - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:hsql://localhost:9001
2005-04-02 16:53:53,298 [http-8080-Processor21] INFO DriverManagerConnectionProvider - connection properties: {user=sa, password=}
2005-04-02 16:53:53,310 [http-8080-Processor21] INFO TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
2005-04-02 16:53:53,545 [http-8080-Processor21] INFO SettingsFactory - Use scrollable result sets: true
2005-04-02 16:53:53,546 [http-8080-Processor21] INFO SettingsFactory - Use JDBC3 getGeneratedKeys(): false
2005-04-02 16:53:53,546 [http-8080-Processor21] INFO SettingsFactory - Optimize cache for minimal puts: false
2005-04-02 16:53:53,547 [http-8080-Processor21] INFO SettingsFactory - Query language substitutions: {}
2005-04-02 16:53:53,548 [http-8080-Processor21] INFO SettingsFactory - cache provider: net.sf.hibernate.cache.EhCacheProvider
2005-04-02 16:53:53,591 [http-8080-Processor21] INFO Configuration - instantiating and configuring caches
2005-04-02 16:53:53,699 [http-8080-Processor21] WARN Configurator - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: file:/Users/vince/Development/workspace/support/exo-tomcat/work/Catalina/localhost/JupiterPortal/loader/ehcache-failsafe.xml


Can anyone point me in the right direction please?


Thanks in advance..

Vince


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 03, 2005 3:33 pm 
Newbie

Joined: Wed Jan 05, 2005 12:30 pm
Posts: 17
Location: Philadelphia, PA
A little better logging of the exception that hibernate throws might help. Can you edit the catch block that logs the stack trace at the top of your post and make it more helpful.

You might be having trouble with the ehcache.xml file. You might edit your own and put it in the root of a folder on the classpath and see if that makes the warning go away. Be sure the disk file setup is a valid.


Top
 Profile  
 
 Post subject: auugggggg...
PostPosted: Sun Apr 03, 2005 5:51 pm 
Newbie

Joined: Tue Mar 22, 2005 10:31 pm
Posts: 8
This is still killing me, been at it all day. Ok here is something really weird. I created a new class called HibernateTest, it's in the same package as my portal class and they both use the same appSession.

----- HibernateTest--

public class HibernateTest {

public static void main(String[] args) {

System.out.println("Test");
Session hibernateSession = AppSession.getSession();
try{
Transaction tx = hibernateSession.beginTransaction();
Interviewer myI = new Interviewer();
myI.setUsername("vcordaro");
myI.setFirstname("Vince");
hibernateSession.save(myI);
tx.commit();
}catch(Exception e)
{
System.out.println("ERROR");
}

}
}


--------------------------------------------
THAT WORKS, really weird.
However when I try to use the exact same AppSession in my portal init, I get errors. So I was thinking that possible I am missing a file or something when I deploy my portlet. Here is a listing of the jars I am deploying, not sure if I need them all, but I have been trying different things..

asm-attrs.jar
asm.jar
cglib-2.1.jar
commons-collections-2.1.1.jar
commons-lang-1.0.1.jar
commons-logging.jar
dom4j-1.5.2.jar
ehcache-1.1.jar
ehcache-failsafe.xml
hibernate-tools.jar
hibernate2.jar
hsqldb.jar
jdo.jar
jdom.jar
jr.jar
jstl.jar
jta.jar
log4j-1.2.9.jar
odmg-3.0.jar
portlet-api-1.0.jar
standard.jar
xerces-2.4.0.jar

----

My error seems is right when the AppSession calls this line:

sessionFactory = myConfiguration.buildSessionFactory();



I just can't figure out why the AppSession will build the session when my test class runs it outside the portal, but it crashes inside the portal.

From my research on the web it appears that this error:

[portletcontainer] [ERROR] exception while initializing portlet : JupiterPortal
null
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:805)

might be a class no found. That's why I was thinking I might be missing a jar. I dug into the Configuration.java file and at line 805 it calls
SessionFactorImpl which is part of which is in the hibernate2.jar. I have no idea what's going on.

Evan I am not exactly sure how I could logg that exception without going into the hibernate code, modifying it and rebuilding the jars. I am not catching that stack trace it's being thrown outside my code.

I also tried moving the ehcache.xml file to remove that WARN and that didn't do anything.

What's also interesting is that the DB is being created even when run in the portal.
new SchemaUpdate(myConfiguration).execute(true, true);

It's the next command after this that causes my error:
sessionFactory = myConfiguration.buildSessionFactory();

So it calls this method:

public SessionFactory buildSessionFactory() throws HibernateException {
secondPassCompile();
validate();
Environment.verifyProperties(properties);
Properties copy = new Properties();
copy.putAll(properties);
Settings settings = buildSettings();
configureCaches(settings);
return new SessionFactoryImpl(this, settings);
}

It gets all the way to the return and spits in error somewhere in the SessionFactoryImpl. I must be missing a file somewhere. That's the only thing I can think of.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 03, 2005 6:54 pm 
Newbie

Joined: Wed Jan 05, 2005 12:30 pm
Posts: 17
Location: Philadelphia, PA
Somewhere there is a catch block that logs the string "exception while initializing portlet". I'm thinking this is not in Hibernate code. If you can find that block of code you can either add more logging or, better yet, fire up a remote debugger (Eclipse which has good docs if you've never done this before) set a breakpoint in that catch block and have a look.

_Evan


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 03, 2005 7:17 pm 
Newbie

Joined: Wed Jan 05, 2005 12:30 pm
Posts: 17
Location: Philadelphia, PA
One more thing:

Code:
try {
      if (sessionFactory == null) initialization();
      return sessionFactory.openSession();
   } catch (Exception e) {
      logger.debug(e);
      return null;
   }



Why do you swallow this here? Why not make getSession() throw HibernateException (It's a RuntimeException in 3.0). What you are doing is effectively guaranteeing that whatever happens, unless you happen to have debugging turned on for this class, will result in a NPE upstream with no other helpful message in the logs.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 4:30 am 
Newbie

Joined: Mon Apr 18, 2005 8:15 am
Posts: 7
Hi,

I have had some strange problems, where the order in which I imported the jar files was the reason to the error. In the hibernate/lib there is a readme file, where the jars needed is listed both runtime and compiletime.
I don't know if this solves your problem, but this was just a thought..:)

/ Anders


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