Hi. I'm having some problems with ehcache, or hibernate, or jboss, or maybe even eclipse.. I'm not really sure.
I've just upgraded from jboss 4.0.3 to 4.0.4GA to take advantage of the new jbossws, but now hibernate is giving me trouble.
When I first deploy to jboss, everything works fine.. the sessionfactory is created, and everything is working as expected.
Then when I try to redeploy The error displayed below is presented. I guess it has something to do with the way my app uses the sessionfactory, or something has changed with the new release of one or more of the parts involved, but I just can't figure it out. I'm using the latest ehcache 1.2.
this is my sessionfactory class:
Code:
package session;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
/**
* Configures and provides access to Hibernate sessions, tied to the
* current thread of execution. Follows the Thread Local Session
*/
public class HibernateSessionFactory {
/**
* Location of hibernate.cfg.xml file.
* NOTICE: Location should be on the classpath as Hibernate uses
* #resourceAsStream style lookup for its configuration file. That
* is place the config file in a Java package - the default location
* is the default Java package.<br><br>
* Examples: <br>
* <code>CONFIG_FILE_LOCATION = "/hibernate.conf.xml".
* CONFIG_FILE_LOCATION = "/com/foo/bar/myhiberstuff.conf.xml".</code>
*/
private static String CONFIG_FILE_LOCATION = "hibernate.cfg.xml";
/** Holds a single instance of Session */
private static final ThreadLocal threadLocal = new ThreadLocal();
/** The single instance of hibernate configuration */
private static final Configuration cfg = new Configuration();
//.addFile("/handleUsers/xml/UserGroup.hbm.xml"); XXX kOFFOR ST?R DETTA HER??
/** The single instance of hibernate SessionFactory */
private static SessionFactory sessionFactory;
/**
* Returns the ThreadLocal Session instance. Lazy initialize
* the <code>SessionFactory</code> if needed.
*
* @return Session
* @throws HibernateException
*/
@SuppressWarnings("unchecked")
public static Session currentSession() throws HibernateException {
Session session = (Session) threadLocal.get();
if (session == null) {
try {
if(sessionFactory == null) {
sessionFactory = cfg.configure(CONFIG_FILE_LOCATION).buildSessionFactory();
}
session = sessionFactory.openSession();
threadLocal.set(session);
}
catch (Exception e) {
System.err.println("%%%% Error Creating SessionFactory%%%%");
e.printStackTrace();
}
}
/*if(!session.isConnected()) {
session.reconnect();
}*/
return session;
}
/**
* Close the single hibernate session instance.
*
* @throws HibernateException
*/
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);
//System.out.println("Closing the session in sessionfactory");
if (session != null) {
session.close();
}
}
/**
* Default constructor.
*/
private HibernateSessionFactory() {
}
}
and this is how it's beeing used:
Code:
/**
* Gets the default value from database
*
* @param strTag
* @return String
*/
public String getDefaultValue(String strTag){
try {
// Get session from sessionfactory and start a new transaction
session = HibernateSessionFactory.currentSession();
transaction = session.beginTransaction();
// Return module based on moduleID
String strValue = session.createQuery( "select value from SystemDefault where tag = '"+strTag +"'").uniqueResult().toString() ;
// Commit transaction and close connection
transaction.commit();
// HibernateSessionFactory.closeSession();
return strValue;
} catch (HibernateException e) {
System.out.println( " EXCEPTION! MainController / getDefaultValue() / HibernateException" +e.getMessage());
e.printStackTrace();
return null;
} catch (Exception e){
System.out.println( " EXCEPTION! MainController / getDefaultValue() / Exception" +e.getMessage() );
e.printStackTrace();
return null;
}
}
Is there anything at all that can/should be done differently? I'm pretty unexperienced at hibernate, so it might be obvious for some..
All help and comments are greatly appreciated! :)
Hibernate version: 3.2 cr2
Mapping documents:This is my hibernate configuration
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.password">123456</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/TRIM</property>
<property name="hibernate.connection.username">admin</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<!-- mapping files -->
<mapping resource="hibernate_xml/Users.hbm.xml" />
<mapping resource="hibernate_xml/Module.hbm.xml" />
<mapping resource="hibernate_xml/ModuleAccess.hbm.xml" />
<mapping resource="hibernate_xml/UserGroup.hbm.xml" />
<mapping resource="hibernate_xml/SystemDefault.hbm.xml" />
<mapping resource="hibernate_xml/RelationType.hbm.xml" />
<mapping resource="hibernate_xml/Relation.hbm.xml" />
<mapping resource="hibernate_xml/Resource.hbm.xml" />
<mapping resource="hibernate_xml/Contact.hbm.xml" />
<mapping resource="hibernate_xml/ResourceType.hbm.xml" />
<mapping resource="hibernate_xml/Unit.hbm.xml" />
<mapping resource="hibernate_xml/ResourceCategory.hbm.xml" />
<mapping resource="hibernate_xml/Activity.hbm.xml" />
<mapping resource="hibernate_xml/ActivityLine.hbm.xml" />
<mapping resource="hibernate_xml/ActivityType.hbm.xml" />
<mapping resource="hibernate_xml/Status.hbm.xml" />
</session-factory>
</hibernate-configuration>
Code between sessionFactory.openSession() and session.close():Full stack trace of any exception that occurs:Code:
12:31:09,408 INFO [Configuration] configuring from resource: hibernate.cfg.xml
12:31:09,409 INFO [Configuration] Configuration resource: hibernate.cfg.xml
12:31:09,430 INFO [Configuration] Reading mappings from resource: hibernate_xml/Users.hbm.xml
12:31:09,470 INFO [HbmBinder] Mapping class: valueObjects.Users -> users
12:31:09,480 INFO [Configuration] Reading mappings from resource: hibernate_xml/Module.hbm.xml
12:31:09,501 INFO [HbmBinder] Mapping class: valueObjects.Module -> module
12:31:09,503 INFO [Configuration] Reading mappings from resource: hibernate_xml/ModuleAccess.hbm.xml
12:31:09,544 INFO [HbmBinder] Mapping class: valueObjects.ModuleAccess -> moduleaccess
12:31:09,545 INFO [Configuration] Reading mappings from resource: hibernate_xml/UserGroup.hbm.xml
12:31:09,560 INFO [HbmBinder] Mapping class: valueObjects.UserGroup -> usergroup
12:31:09,561 INFO [Configuration] Reading mappings from resource: hibernate_xml/SystemDefault.hbm.xml
12:31:09,575 INFO [HbmBinder] Mapping class: valueObjects.SystemDefault -> systemdefault
12:31:09,576 INFO [Configuration] Reading mappings from resource: hibernate_xml/RelationType.hbm.xml
12:31:09,588 INFO [HbmBinder] Mapping class: valueObjects.RelationType -> relationtype
12:31:09,593 INFO [Configuration] Reading mappings from resource: hibernate_xml/Relation.hbm.xml
12:31:09,660 INFO [HbmBinder] Mapping class: valueObjects.Relation -> relation
12:31:09,666 INFO [Configuration] Reading mappings from resource: hibernate_xml/Resource.hbm.xml
12:31:09,689 INFO [HbmBinder] Mapping class: valueObjects.Resource -> resource
12:31:09,694 INFO [Configuration] Reading mappings from resource: hibernate_xml/Contact.hbm.xml
12:31:09,718 INFO [HbmBinder] Mapping class: valueObjects.Contact -> contact
12:31:09,721 INFO [Configuration] Reading mappings from resource: hibernate_xml/ResourceType.hbm.xml
12:31:09,744 INFO [HbmBinder] Mapping class: valueObjects.ResourceType -> resourcetype
12:31:09,750 INFO [Configuration] Reading mappings from resource: hibernate_xml/Unit.hbm.xml
12:31:09,766 INFO [HbmBinder] Mapping class: valueObjects.Unit -> unit
12:31:09,767 INFO [Configuration] Reading mappings from resource: hibernate_xml/ResourceCategory.hbm.xml
12:31:09,789 INFO [HbmBinder] Mapping class: valueObjects.ResourceCategory -> resourcecategory
12:31:09,792 INFO [Configuration] Reading mappings from resource: hibernate_xml/Activity.hbm.xml
12:31:09,821 INFO [HbmBinder] Mapping class: valueObjects.Activity -> activity
12:31:09,829 INFO [Configuration] Reading mappings from resource: hibernate_xml/ActivityLine.hbm.xml
12:31:09,870 INFO [HbmBinder] Mapping class: valueObjects.ActivityLine -> activityline
12:31:09,890 INFO [Configuration] Reading mappings from resource: hibernate_xml/ActivityType.hbm.xml
12:31:09,924 INFO [HbmBinder] Mapping class: valueObjects.ActivityType -> activitytype
12:31:09,930 INFO [Configuration] Reading mappings from resource: hibernate_xml/Status.hbm.xml
12:31:10,001 INFO [HbmBinder] Mapping class: valueObjects.Status -> status
12:31:10,003 INFO [Configuration] Configured SessionFactory: null
12:31:10,016 WARN [RootClass] composite-id class does not override equals(): valueObjects.ModuleAccess
12:31:10,017 WARN [RootClass] composite-id class does not override hashCode(): valueObjects.ModuleAccess
12:31:10,020 INFO [DriverManagerConnectionProvider] Using Hibernate built-in connection pool (not for production use!)
12:31:10,021 INFO [DriverManagerConnectionProvider] Hibernate connection pool size: 20
12:31:10,022 INFO [DriverManagerConnectionProvider] autocommit mode: false
12:31:10,023 INFO [DriverManagerConnectionProvider] using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost:5432/TRIM
12:31:10,026 INFO [DriverManagerConnectionProvider] connection properties: {user=admin, password=123456}
12:31:10,042 INFO [SettingsFactory] RDBMS: PostgreSQL, version: 8.0.4
12:31:10,043 INFO [SettingsFactory] JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.0 JDBC3 with SSL (build 314)
12:31:10,046 INFO [Dialect] Using dialect: org.hibernate.dialect.PostgreSQLDialect
12:31:10,048 INFO [TransactionFactoryFactory] Using default transaction strategy (direct JDBC transactions)
12:31:10,048 INFO [TransactionManagerLookupFactory] No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
12:31:10,049 INFO [SettingsFactory] Automatic flush during beforeCompletion(): disabled
12:31:10,050 INFO [SettingsFactory] Automatic session close at end of transaction: disabled
12:31:10,051 INFO [SettingsFactory] JDBC batch size: 15
12:31:10,052 INFO [SettingsFactory] JDBC batch updates for versioned data: disabled
12:31:10,052 INFO [SettingsFactory] Scrollable result sets: enabled
12:31:10,053 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): disabled
12:31:10,054 INFO [SettingsFactory] Connection release mode: auto
12:31:10,055 INFO [SettingsFactory] Default batch fetch size: 1
12:31:10,055 INFO [SettingsFactory] Generate SQL with comments: disabled
12:31:10,056 INFO [SettingsFactory] Order SQL updates by primary key: disabled
12:31:10,057 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
12:31:10,059 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
12:31:10,059 INFO [SettingsFactory] Query language substitutions: {}
12:31:10,060 INFO [SettingsFactory] Second-level cache: enabled
12:31:10,061 INFO [SettingsFactory] Query cache: disabled
12:31:10,062 INFO [SettingsFactory] Cache provider: org.hibernate.cache.EhCacheProvider
12:31:10,064 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
12:31:10,064 INFO [SettingsFactory] Structured second-level cache entries: disabled
12:31:10,065 INFO [SettingsFactory] Statistics: disabled
12:31:10,066 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
12:31:10,067 INFO [SettingsFactory] Default entity-mode: pojo
12:31:10,104 INFO [SessionFactoryImpl] building session factory
12:31:10,107 WARN [ConfigurationFactory] No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/home/borre/jboss-4.0.4.GA/server/default/lib/ehcache-1.2.jar!/ehcache-failsafe.xml
12:31:10,124 ERROR [STDERR] %%%% Error Creating SessionFactory%%%%
12:31:10,126 ERROR [STDERR] org.hibernate.cache.CacheException: Attempt to restart an already started EhCacheProvider. Use sessionFactory.close() between repeated calls to buildSessionFactory. Consider using net.sf.ehcache.hibernate.SingletonEhCacheProvider. Error from ehcache was: Cannot parseConfiguration CacheManager. Attempt to create a new instance of CacheManager using the diskStorePath "/tmp" which is already used by an existing CacheManager. The source of the configuration was classpath.
at org.hibernate.cache.EhCacheProvider.start(EhCacheProvider.java:133)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:180)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1213)
at session.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:52)
at main.MainController.getDefaultValue(MainController.java:246)
at main.LanguageController.<init>(LanguageController.java:45)
at org.apache.jsp.login_jsp._jspService(login_jsp.java:47)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:574)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:499)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:966)
at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:614)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:196)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)
12:31:10,128 INFO [STDOUT] EXCEPTION! MainController / getDefaultValue() / Exceptionnull
12:31:10,129 ERROR [STDERR] java.lang.NullPointerException
12:31:10,130 ERROR [STDERR] at main.MainController.getDefaultValue(MainController.java:247)
12:31:10,131 ERROR [STDERR] at main.LanguageController.<init>(LanguageController.java:45)
12:31:10,132 ERROR [STDERR] at org.apache.jsp.login_jsp._jspService(login_jsp.java:47)
12:31:10,132 ERROR [STDERR] at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
12:31:10,133 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
12:31:10,134 ERROR [STDERR] at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
12:31:10,135 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
12:31:10,137 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
12:31:10,138 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
12:31:10,139 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
12:31:10,139 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
12:31:10,140 ERROR [STDERR] at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
12:31:10,141 ERROR [STDERR] at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:574)
12:31:10,142 ERROR [STDERR] at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:499)
12:31:10,143 ERROR [STDERR] at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:966)
12:31:10,143 ERROR [STDERR] at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:614)
12:31:10,144 ERROR [STDERR] at org.apache.jsp.index_jsp._jspService(index_jsp.java:196)
12:31:10,147 ERROR [STDERR] at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
12:31:10,147 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
12:31:10,148 ERROR [STDERR] at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
12:31:10,148 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
12:31:10,148 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
12:31:10,149 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
12:31:10,149 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
12:31:10,149 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
12:31:10,150 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
12:31:10,150 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
12:31:10,150 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
12:31:10,151 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
12:31:10,151 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
12:31:10,151 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
12:31:10,152 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
12:31:10,152 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
12:31:10,152 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
12:31:10,153 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
12:31:10,153 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
12:31:10,154 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
12:31:10,154 ERROR [STDERR] at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
12:31:10,154 ERROR [STDERR] at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
12:31:10,155 ERROR [STDERR] at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
12:31:10,155 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595)
12:31:10,157 INFO [STDOUT] Missing languagefile:null.txt
12:31:52,871 INFO [DriverManagerConnectionProvider] cleaning up connection pool: jdbc:postgresql://localhost:5432/TRIM
Name and version of the database you are using: PostgreSQL, version: 8.0.4