[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