-->
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.  [ 3 posts ] 
Author Message
 Post subject: Tomcat Datasource not available. No JBoss used
PostPosted: Wed Feb 23, 2005 4:28 pm 
Newbie

Joined: Wed Feb 23, 2005 3:34 pm
Posts: 16
Location: Irving, Tx
[b]A brief overview to start:[/b]
I have an existing app that we're trying to evaluate porting to hibernate. The existing app works with the Tomcat/JNDI datasource described here. I am only trying to get one table and it's relative mapping set up in order to judge how much effort is involved in getting the entire app converted. I have used IntelliJ plug-in to generate a SponsorInfo.hbm.xml.. seems to be parsing ok per logs below. The datasource lookup is not cooperating. Any help would be appreciated.

One more note: I noticed references to JBoss in other config files I've seen online such as
<!--
<property name="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">net.sf.hibernate.transaction.JBossTransactionManagerLookup</property>
<property name="hibernate.dialect">net.sf.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.connection.provider_class">com.opensourceconnections.msjdbcproxy.HibernateProvider</property>
<property name="hibernate.query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
-->

[b]Are these used in a JBoss/Tomcat combined architecture only?
What are the required parameters w/o JBoss?[/b]

[b]Hibernate version:[/b]2.1.8

[b]Mapping documents:[/b] hibernate.hbm.cfg
<session-factory name="java:/hibernate/HibernateFactory">
<property name="connection.datasource">java:/jdbc/RME</property>
<property name="connection.username">xyz</property>
<property name="connection.password">notReallyXYZ</property>
<property name="show_sql">true</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>

<mapping resource="/com/ccistech/rme/datamap/SponsorInfo.hbm.xml"/>
<!-- mapping resource="hibernate.hbm.xml"/ -->
</session-factory>

[b]Code between sessionFactory.openSession() and session.close():[/b]
--as found on the web:
public class HibernatePlugin implements PlugIn {
private Configuration config;
private SessionFactory factory;

// Struts-config.xml references the following cfg also..
//plus, it's in the WEB-INF/classes directory where it is actually loading
//(based on changes found)

private String path = "/hibernate.cfg.xml";
private static Class clazz = HibernatePlugin.class;

public static final String KEY_NAME = clazz.getName();

private static Log log = LogFactory.getLog(clazz);

public void setPath(String path) {
this.path = path;
}

public void init(ActionServlet servlet, ModuleConfig modConfig)
throws ServletException {

try {
URL url = HibernatePlugin.class.getResource(path);
config = new Configuration().configure(url);
factory = config.buildSessionFactory();
servlet.getServletContext().setAttribute(KEY_NAME, factory);

} catch (MappingException e) {
log.error("mapping error", e);
throw new ServletException();

} catch (HibernateException e) {
log.error("hibernate error", e);
throw new ServletException();
}

}

public void destroy() {
try {
factory.close();
} catch (HibernateException e) {
log.error("unable to close factory", e);
}
}
}

[b]Full stack trace of any exception that occurs:[/b]
net.sf.hibernate.HibernateException: Could not find datasource
at net.sf.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:48)
at net.sf.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:83)
at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:76)
at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1172)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:803)
at com.ccistech.rme.portal.util.HibernatePlugin.init(HibernatePlugin.java:37)
at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:1158)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:473)
at javax.servlet.GenericServlet.init(GenericServlet.java:256)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1044)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:887)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3960)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4283)
at org.apache.catalina.core.StandardContext.reload(StandardContext.java:2992)
at org.apache.catalina.core.StandardContext.backgroundProcess(StandardContext.java:4586)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1659)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1668)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1668)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1648)
at java.lang.Thread.run(Thread.java:534)
Caused by: javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:814)
at org.apache.naming.NamingContext.lookup(NamingContext.java:197)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:183)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at net.sf.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:44)
... 19 more

[b]Name and version of the database you are using:[/b]
MySQL 4.0.16 NT

[b]The generated SQL (show_sql=true):[/b]
N/A
I'm using Tomcat 5.0.18, Not using JBoss

server.xml
<Resource name="jdbc/RME"
auth="Container"
type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/RME">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>

[b]Debug level Hibernate log excerpt:[/b]
2005-02-23 12:59:47,946 DEBUG org.apache.commons.digester.Digester - Fire end() for SetPropertiesRule[]
2005-02-23 12:59:47,962 DEBUG org.apache.commons.digester.Digester - Fire end() for ObjectCreateRule[className=org.apache.commons.validator.FormSet, attributeName=className]
2005-02-23 12:59:47,962 DEBUG org.apache.commons.digester.Digester - [ObjectCreateRule]{form-validation/formset} Pop org.apache.commons.validator.FormSet
2005-02-23 12:59:47,962 DEBUG org.apache.commons.digester.Digester.sax - ignorableWhitespace(
)
2005-02-23 12:59:47,962 DEBUG org.apache.commons.digester.Digester.sax - endElement(,form-validation,form-validation)
2005-02-23 12:59:47,962 DEBUG org.apache.commons.digester.Digester - match='form-validation'
2005-02-23 12:59:47,962 DEBUG org.apache.commons.digester.Digester - bodyText=''
2005-02-23 12:59:47,962 DEBUG org.apache.commons.digester.Digester - No rules found matching 'form-validation'.
2005-02-23 12:59:47,962 DEBUG org.apache.commons.digester.Digester - Popping body text ''
2005-02-23 12:59:47,962 DEBUG org.apache.commons.digester.Digester.sax - endDocument()
2005-02-23 12:59:48,025 DEBUG org.apache.commons.beanutils.BeanUtils - BeanUtils.populate(com.ccistech.rme.portal.util.HibernatePlugin@5a936b, {path=/hibernate.cfg.xml})
2005-02-23 12:59:48,025 DEBUG org.apache.commons.beanutils.BeanUtils - setProperty(com.ccistech.rme.portal.util.HibernatePlugin@5a936b, path, /hibernate.cfg.xml)
2005-02-23 12:59:48,056 DEBUG org.apache.commons.beanutils.ConvertUtils - Convert string '/hibernate.cfg.xml' to class 'java.lang.String'
2005-02-23 12:59:48,056 DEBUG org.apache.commons.beanutils.ConvertUtils - Using converter org.apache.commons.beanutils.converters.StringConverter@2b7bd9
2005-02-23 12:59:48,134 INFO net.sf.hibernate.cfg.Environment - Hibernate 2.1.8
2005-02-23 12:59:48,134 INFO net.sf.hibernate.cfg.Environment - hibernate.properties not found
2005-02-23 12:59:48,150 INFO net.sf.hibernate.cfg.Environment - using CGLIB reflection optimizer
2005-02-23 12:59:48,150 INFO net.sf.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
2005-02-23 12:59:48,196 INFO net.sf.hibernate.cfg.Configuration - configuring from url: file:/C:/workspace/ccistech/WEB-INF/classes/hibernate.cfg.xml
2005-02-23 12:59:48,243 DEBUG net.sf.hibernate.util.DTDEntityResolver - trying to locate http://hibernate.sourceforge.net/hibern ... on-2.0.dtd in classpath under net/sf/hibernate/
2005-02-23 12:59:48,259 DEBUG net.sf.hibernate.util.DTDEntityResolver - found http://hibernate.sourceforge.net/hibern ... on-2.0.dtd in classpath
2005-02-23 12:59:48,275 DEBUG net.sf.hibernate.cfg.Configuration - connection.datasource=java:/jdbc/RME
2005-02-23 12:59:48,275 DEBUG net.sf.hibernate.cfg.Configuration - connection.username=xyz
2005-02-23 12:59:48,275 DEBUG net.sf.hibernate.cfg.Configuration - connection.password=notReallyXYZ
2005-02-23 12:59:48,275 DEBUG net.sf.hibernate.cfg.Configuration - show_sql=true
2005-02-23 12:59:48,275 DEBUG net.sf.hibernate.cfg.Configuration - dialect=net.sf.hibernate.dialect.MySQLDialect
2005-02-23 12:59:48,275 DEBUG net.sf.hibernate.cfg.Configuration - java:/hibernate/HibernateFactory<-org.dom4j.tree.DefaultAttribute@106dc2d [Attribute: name resource value "/com/ccistech/rme/datamap/SponsorInfo.hbm.xml"]
2005-02-23 12:59:48,275 INFO net.sf.hibernate.cfg.Configuration - Mapping resource: /com/ccistech/rme/datamap/SponsorInfo.hbm.xml
2005-02-23 12:59:48,290 DEBUG net.sf.hibernate.util.DTDEntityResolver - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
2005-02-23 12:59:48,290 DEBUG net.sf.hibernate.util.DTDEntityResolver - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
2005-02-23 12:59:48,837 INFO net.sf.hibernate.cfg.Binder - Mapping class: com.ccistech.rme.portal.promotions.SponsorInfo -> SPONSOR_INFO
2005-02-23 12:59:48,915 DEBUG net.sf.hibernate.cache.CacheFactory - cache for: com.ccistech.rme.portal.promotions.SponsorInfo usage strategy: read-write
2005-02-23 12:59:49,665 DEBUG net.sf.hibernate.cfg.Binder - Mapped property: sponsorId -> SPONSOR_ID, type: string
2005-02-23 12:59:49,806 DEBUG net.sf.hibernate.cfg.Binder - Mapped property: sponsorName -> SPONSOR_NAME, type: string
2005-02-23 12:59:49,806 DEBUG net.sf.hibernate.cfg.Binder - Mapped property: userDefKey -> USER_DEFINED_KEY, type: string
2005-02-23 12:59:49,806 INFO net.sf.hibernate.cfg.Configuration - Configured SessionFactory: java:/hibernate/HibernateFactory
2005-02-23 12:59:49,806 DEBUG net.sf.hibernate.cfg.Configuration - properties: {show_sql=true, connection.datasource=java:/jdbc/RME, java.runtime.version=1.4.2-b28, user.name=rosengd, hibernate.session_factory_name=java:/hibernate/HibernateFactory, user.language=en, java.naming.factory.initial=org.apache.naming.java.javaURLContextFactory, dialect=net.sf.hibernate.dialect.MySQLDialect, java.version=1.4.2, hibernate.connection.datasource=java:/jdbc/RME, connection.password=notReallyXYZ, hibernate.connection.password=notReallyXYZ, hibernate.connection.username=xyz, connection.username=xyz, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.show_sql=true}
2005-02-23 12:59:49,806 INFO net.sf.hibernate.cfg.Configuration - processing one-to-many association mappings
2005-02-23 12:59:49,806 INFO net.sf.hibernate.cfg.Configuration - processing one-to-one association property references
2005-02-23 12:59:49,806 INFO net.sf.hibernate.cfg.Configuration - processing foreign key constraints
2005-02-23 12:59:50,040 INFO net.sf.hibernate.dialect.Dialect - Using dialect: net.sf.hibernate.dialect.MySQLDialect
2005-02-23 12:59:50,071 DEBUG net.sf.hibernate.exception.SQLExceptionConverterFactory - Using dialect defined converter
2005-02-23 12:59:50,150 INFO net.sf.hibernate.cfg.SettingsFactory - Maximim outer join fetch depth: 2
2005-02-23 12:59:50,150 INFO net.sf.hibernate.cfg.SettingsFactory - Use outer join fetching: true
2005-02-23 13:00:53,728 INFO net.sf.hibernate.util.NamingHelper - JNDI InitialContext properties:{}
2005-02-23 13:00:54,587 FATAL net.sf.hibernate.connection.DatasourceConnectionProvider - Could not find datasource: java:/jdbc/RME
// I've also tried "jdbc/RME", "java:env/jdbc/RME" ..among others


Top
 Profile  
 
 Post subject: resolved
PostPosted: Wed Feb 23, 2005 7:09 pm 
Newbie

Joined: Wed Feb 23, 2005 3:34 pm
Posts: 16
Location: Irving, Tx
I found a reasonable explanation in the hibernate FAQs under a similar topic -
"Tomcat throws java.lang.UnsupportedOperationException when fetching a JDBC connection". See the FAQ for the details. I'll post the working cfg, but also mention that I debugged to see an error thrown that I would not have caught in the logs.

The session factory is trying to bind to JNDI based on the
<session-factory name=.. > in my hibernate.cfg.xml (not supported in Tomcat), just omit this in the session-factory tag and it should be fine. There are other posts related to how to programmatically bind/reference the session factory as a singleton.

My fix: removed connection.user and connection.password from the cfg. I also added to the config the lines below regarding transaction.factory_class and jta.UserTransaction, but I'm not certain that it was any benefit.

<hibernate-configuration>
<!--session-factory name="java:/hibernate/HibernateFactory" -->
<session-factory>
<property name="connection.datasource">java:comp/env/jdbc/RME</property>
<!-- property name="connection.datasource">java:comp/jdbc/RME</property -->
<!-- property name="connection.datasource">jdbc/RME</property -->
<!-- property name="connection.datasource">/jdbc/RME</property -->
<!--property name="connection.username"></property>
<property name="connection.password"></property
-->
<property name="show_sql">true</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="transaction.factory_class">
net.sf.hibernate.transaction.JTATransactionFactory
</property>
<property name="jta.UserTransaction">java:comp/UserTransaction</property>

<mapping resource="/com/ccistech/rme/datamap/SponsorInfo.hbm.xml"/>
<!-- mapping resource="hibernate.hbm.xml"/ -->
</session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject: Exception when factory attempts to get session object.
PostPosted: Thu Feb 24, 2005 4:49 pm 
Newbie

Joined: Wed Feb 23, 2005 3:34 pm
Posts: 16
Location: Irving, Tx
My initial problem was evident as Tomcat failed to start. Struts was refencing the hibernate plugin Class, and failed to create or register the factory via JNDI.

NOW, I'm trying to use the singleton approach...The factory is ok and the application starts. It throws a nullPointer Exception in my action (helper) class prior to attemting my first query. Stepping into the code, it's the factory.openSession() that fails. The interfaces involved are proving tricky to step into. Does anyone have tips on what to do next? The stack trace references the action class hitting the null session, so it's not helpful, but listed last anyway.

hibernate.hbm.cfg--------
<hibernate-configuration>
<session-factory>
<property name="connection.datasource">java:comp/env/jdbc/RME</property>


<property name="show_sql">true</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>

<mapping resource="/com/ccistech/rme/datamap/SponsorInfo.hbm.xml"/>
<!-- mapping resource="hibernate.hbm.xml"/ -->
</session-factory>
</hibernate-configuration>

source accessing session -----
***
final public static String HQL_FIND_LIKE_SPONSOR =
"from com.ccistech.rme.portal.promotions.SponsorInfo as e where e.? like ?";
***
public List findLikeSponsorsHibernate(ActionServlet servlet, String type, String param)
throws HibernateException
{
// type is a column name and param is the value to search

Sponsor sponsor = null;
List sponsors = null;
SessionFactory factory = null;
Session session = null;
try {
String key = HibernatePlugin.KEY_NAME;
factory =
(SessionFactory) servlet.getServletContext()
.getAttribute(key);

session = factory.openSession(); // EXCEPTION HERE

// session = HibernateUtil.currentSession();

sponsors =
session.find(
HQL_FIND_LIKE_SPONSOR,
new Object[]{type},
new Type[]{Hibernate.STRING});

if (!sponsors.isEmpty()) {
sponsor = (Sponsor) sponsors.get(0);
}

} catch (HibernateException e) {
logger.error("Hibernate error", e);
} finally {
logger.error("Hibernate exception encountered");
session.close();
}
if (sponsors == null){
return new ArrayList();
}
return sponsors;
}

init servlet referenced by struts-cfg.xml plugin tag ----------package com.ccistech.rme.portal.util;

import java.net.URL;
import javax.servlet.ServletException;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.MappingException;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;

public class HibernatePlugin implements PlugIn {
private Configuration config;
private SessionFactory factory;
private String path = "/hibernate.cfg.xml";
private static Class clazz = HibernatePlugin.class;

public static final String KEY_NAME = clazz.getName();

private static Log log = LogFactory.getLog(clazz);

public void setPath(String path) {
this.path = path;
}

public void init(ActionServlet servlet, ModuleConfig modConfig)
throws ServletException {

try {
URL url = HibernatePlugin.class.getResource(path);
config = new Configuration().configure(url);
factory = config.buildSessionFactory();
servlet.getServletContext().setAttribute(KEY_NAME, factory);

} catch (MappingException e) {
log.error("mapping error", e);
throw new ServletException();

} catch (HibernateException e) {
log.error("hibernate error", e);
throw new ServletException();
}

}

public void destroy() {
try {
factory.close();
} catch (HibernateException e) {
log.error("unable to close factory", e);
}
}
}


--- see my previous post for remainder of my settings,
and thanks!

java.lang.NullPointerException
at com.ccistech.rme.portal.promotions.SponsorRW.findLikeSponsorsHibernate(SponsorRW.java:388)
at com.ccistech.rme.portal.promotions.SponsorHBSearchAction.getSponsorList(SponsorHBSearchAction.java:138)
at com.ccistech.rme.portal.promotions.SponsorHBSearchAction.execute(SponsorHBSearchAction.java:73)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
at com.ccistech.rme.portal.util.RmeSessionFilter.doFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:257)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:195)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:578)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:206)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)


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