-->
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: Hibern8IDE and Datasource and Tomcat - HELP PLEASE
PostPosted: Wed Jul 14, 2004 10:37 am 
Beginner
Beginner

Joined: Mon Dec 08, 2003 12:15 am
Posts: 47
In the hibern8ide installation instructions, it says the you can add the hibern8ide.jar to a hibernate enabled project within eclipse.

Can someone tell me exactly what a hibernate enabled project is. I am trying to use this tool and since my datasource is configured in tomcat through jndi, I need to use this tool inside my web application environment. I have read through some postings and searched on google, but I can't find anything that will tell me step by step how to integrate this tool in tomcat.

If anybody has accomplished this, I would appreciate it if you could explain to me how you got this to work.

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 14, 2004 1:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Create your sessionfactory and call

Code:
Hibern8IDE.startWith(yourSessionFactory);


And a hibernate enabled project is just a project in which you already have configured hibernate...

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Hibern8IDE and Datasource and Tomcat - HELP PLEASE
PostPosted: Wed Jul 14, 2004 6:14 pm 
Beginner
Beginner

Joined: Mon Dec 08, 2003 12:15 am
Posts: 47
Okay I tried that but since my datasource is configured through jndi in tomcat, hibern8ide can't find my datasource.

I made sure tomcat is running when I tried to start it.

Any more suggestions???


FATAL [main] (DatasourceConnectionProvider.java:47) - Could not find datasource: java:comp/env/jdbc/securanceDatasource
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:640)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at net.sf.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:44)
at net.sf.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:83)
at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:64)
at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1091)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:737)
at com.securance.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:28)
at com.securance.util.StartHibern8IDE.main(StartHibern8IDE.java:15)
ERROR [main] (HibernateUtil.java:32) - Caught HibernateException
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:64)
at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1091)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:737)
at com.securance.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:28)
at com.securance.util.StartHibern8IDE.main(StartHibern8IDE.java:15)
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:640)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at net.sf.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:44)
... 6 more


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 14, 2004 6:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Try launching HibernateIDE from within a Servlet :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 23, 2004 4:26 pm 
Beginner
Beginner

Joined: Fri Mar 12, 2004 8:40 pm
Posts: 30
Location: SF Bay Area
The following solution works for Tomcat 4.0.3 ...

It shouldn't matter what your IDE is ...

I have the following hibernate.cfg.xml file. Note the property for
connection.provider_class :


<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"

"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>

<session-factory>
<property name="connection.provider_class">com.rhi.bob.common.dao.HibernateConnectionProvider</property>
<property name="dialect">net.sf.hibernate.dialect.OracleDialect</property>
<property name="show_sql">true</property>
<property name="transaction.factory_class">net.sf.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.cache.provider_class">net.sf.hibernate.cache.HashtableCacheProvider</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="com/rhi/bob/webfo/forms/beans/impl/FormImpl.hbm.xml"/>
</hibernate-configuration>


And this class,HibernateConnectionProvider,
to establish a DB connection vi JNDI :

package com.rhi.bob.common.dao;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.Context;
import javax.sql.DataSource;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.connection.ConnectionProvider;

public class HibernateConnectionProvider implements ConnectionProvider
{
private static final String DATASOURCE = "java:comp/env/jdbc/RFDSRef";
private String dsName;
private DataSource ds;

public void configure( Properties props ) throws HibernateException {
dsName = DATASOURCE;
try {
Context ctx = new InitialContext();
ds = (DataSource)ctx.lookup( DATASOURCE );
} catch ( NamingException nx ) {
System.out.println(nx.getMessage());
throw new HibernateException( nx.getMessage());
}
if ( this.ds == null ) {
String msg = "invalid hibernate source specified : " + this.dsName;
System.out.println( msg );
throw new HibernateException( msg );
}
}
public Connection getConnection() throws SQLException {
return this.ds.getConnection();
}

public void closeConnection( Connection con ) throws SQLException {
con.close();
}

public void close() throws HibernateException {
System.out.println( "shutting down hibernate source : " + this.dsName );
}

}


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.