-->
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: Could not find datasource
PostPosted: Thu Nov 13, 2003 7:30 am 
Newbie

Joined: Thu Nov 13, 2003 6:09 am
Posts: 7
Hallo,

I get the following error message executing a little test
programm (Tomcat, WSAD, MSSQL Server 2000):

500 [http8080-Processor4] INFO dialect.Dialect - Using dialect: net.sf.hibernate.dialect.SybaseDialect
500 [http8080-Processor4] INFO cfg.SettingsFactory - Use outer join fetching: false
500 [http8080-Processor4] INFO util.NamingHelper - JNDI InitialContext properties:{}
515 [http8080-Processor4] FATAL connection.DatasourceConnectionProvider - Could not find datasource: java:comp/env/jdbc/demo
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:811)
at org.apache.naming.NamingContext.lookup(NamingContext.java:181)
at org.apache.naming.NamingContext.lookup(NamingContext.java:822)
at org.apache.naming.NamingContext.lookup(NamingContext.java:181)
at org.apache.naming.NamingContext.lookup(NamingContext.java:822)
at org.apache.naming.NamingContext.lookup(NamingContext.java:194)
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)
at net.sf.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:83)
at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:64)


<Hibernate.cfg.xml>
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>

<session-factory>

<property name="connection.datasource">java:comp/env/jdbc/demo</property>
<property name="show_sql">true</property>
<property name="use_outer_join">false</property>
<property name="dialect">net.sf.hibernate.dialect.SybaseDialect</property>

<!-- Mapping files -->
<mapping resource="TestClass.hbm.xml"/>

</session-factory>

</hibernate-configuration>



<server.xml>

<Context path="/demo" docBase="demo">
<Resource name="jdbc/demo" scope="Shareable" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/demo">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<!-- DBCP database connection settings -->
<parameter>
<name>url</name>
<value>jdbc:microsoft:sqlserver://ASTERIX:1433;DatabaseName=Diplom</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbcx.sqlserver.SQLServerDataSource</value>
</parameter>
<parameter>
<name>driverName</name>
<value>SQLServer</value>
</parameter>

<parameter>
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<name>password</name>
<value>xxx</value>
</parameter>
<!-- DBCP connection pooling options -->
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>4</value>
</parameter>
</ResourceParams>
</Context>

<Programm code>
try {
sf = new Configuration().configure().buildSessionFactory();
Session session = sf.openSession();
TestClass tc = new TestClass();
Transaction t = session.beginTransaction();
tc.setDescription("TESTTEST");
session.save(tc);
t.commit();
session.close();
} catch (HibernateException e) {
}

I hope someone can help me.

Thanks,
Stephan


Top
 Profile  
 
 Post subject: It's partially Tomcat,partially you
PostPosted: Thu Nov 13, 2003 11:51 am 
Regular
Regular

Joined: Sun Sep 21, 2003 11:43 pm
Posts: 85
Location: Massachusetts
I've tried it and you can't use hibernate with a Tomcat JNDI beginning "java:comp/env". In tomcat, that is a read-only Context, which cannot be updated.

So, I changed mine to a random name "dgf:/hibernate/SessionFactory" and got it to work after I added the 'name' attribute for the session tag in my hibernate.cfg.xml file. I believe it is called 'hibernate.jndi.url' if you use a hibernate.properties file instead of a hibernate.cfg.xml file.

My previous posting with an example for JNDI, is at:
http://forum.hibernate.org/viewtopic.ph ... highlight=

Regards,
David


Top
 Profile  
 
 Post subject: Tomcat needs an entry in the web.xml
PostPosted: Thu Nov 13, 2003 4:43 pm 
Newbie

Joined: Tue Nov 04, 2003 3:04 pm
Posts: 4
I had this same error and you need an entry in the context/WEB-INF/web.xml file that lets that context use the jdbc connection. Here is the listing I have in my web.xml:

<res-ref-name>jdbc/quickstart</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Sharable</res-sharing-scope>
</resource-ref>

You should then be able to connect using the following hibernate.cfg.xml file:


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

<hibernate-configuration>

<session-factory>

<property name="connection.datasource">java:comp/env/jdbc/quickstart</property>
<property name="show_sql">false</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>

<!-- Mapping files -->
<mapping resource="Cat.hbm.xml"/>

</session-factory>

</hibernate-configuration>

Of course you will need to change the dialect to your database type.

Regards;
Nelm


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 14, 2003 7:26 am 
Newbie

Joined: Thu Nov 13, 2003 6:09 am
Posts: 7
@nelm646: I tried it but now I get the following error:

515 [http8080-Processor2] INFO cfg.SettingsFactory - Use outer join fetching: false
515 [http8080-Processor2] INFO util.NamingHelper - JNDI InitialContext properties:{}
547 [http8080-Processor2] INFO connection.DatasourceConnectionProvider - Using datasource: java:comp/env/jdbc/demo
547 [http8080-Processor2] INFO transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
562 [http8080-Processor2] WARN cfg.SettingsFactory - Could not obtain connection metadata
org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null', cause:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:243)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:743)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:518)
at net.sf.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:59)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 14, 2003 7:41 am 
Newbie

Joined: Thu Nov 13, 2003 6:09 am
Posts: 7
@humble

where do I have to insert the "dgf:/hibernate/SessionFactory" ? Can you please tell me some more details, because I'm very new within this topic.

Thanks,

Stephan


Top
 Profile  
 
 Post subject: jndi example for a hibernate.cfg.xml file
PostPosted: Fri Nov 14, 2003 11:15 am 
Regular
Regular

Joined: Sun Sep 21, 2003 11:43 pm
Posts: 85
Location: Massachusetts
Using your last posted example, just add name="something" to the session-factory tag:

Hibernate.cfg.xml>
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>

<session-factory name="dgf:/hibernate/SessionFactory">

<property name="connection.datasource">java:comp/env/jdbc/demo</property>
<property name="show_sql">true</property>
<property name="use_outer_join">false</property>
<property name="dialect">net.sf.hibernate.dialect.SybaseDialect</property>

<!-- Mapping files -->
<mapping resource="TestClass.hbm.xml"/>

</session-factory>

</hibernate-configuration>


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.