aspose file tools*
The moose likes Object Relational Mapping and the fly likes Could not find datasource !!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Could not find datasource !!!" Watch "Could not find datasource !!!" New topic
Author

Could not find datasource !!!

Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 268
Hi All,
Could anyone please tell me why I am getting Could not find datasource excetpion in this hibernate.cfg.xml file

hibernate.cfg.xml
-----------------

<blockquote>code:
<pre name="code" class="core">
<hibernate-configuration>

<session-factory>

<property name="hibernate.connection.datasource">java:MySqlDS</property>
<property name="hibernate.session_factory_name">java:hibernate/SessionFactory/Siddharth</property>
<property name="hibernate.jndi.url"></property>
<property name="hibernate.jndi.class"></property>
<property name="hibernate.connection.username"></property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

<property name="show_sql">true</property>
<property name="format_sql">true</property>

<!-- Show and print nice SQL on stdout. -->
<!-- <property name="dialect">org.hibernate.dialect.MySQLDialect</property> -->
<property name="hibernate.hbm2ddl.auto">create</property>

<!-- List of XML Mapping files -->
<mapping resource="contact.hbm.xml"/>
<!-- <mapping resource="address.hbm.xml"/> -->

</session-factory>

</hibernate-configuration>

</pre>
</blockquote>

I am not able to find the root cause. Please Help !!!
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

<property name="hibernate.jndi.url"></property>
<property name="hibernate.jndi.class"></property>
<property name="hibernate.connection.username"></property>
<property name="hibernate.connection.password"></property>


Could some of these blank properties be a problem?

Where do you set the name of the datasource?

-Cameron McKenzie
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 268
Hi,
I tried the code after removing the blank properties fields. But got the same exception. As these fields are optional these shouldn't affect the outcome if not given. I set the name of the datasource in the file mysql-ds.xml which is in the server\default\deploy directory of JBoss. Also JBoss gives the following line in the startup:


14:12:44,577 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=MySqlDS' to JNDI name 'java:MySqlDS'

contents of mysql-ds.xml :
--------------------------

<blockquote>code:
<pre name="code" class="core">
<datasources>
<local-tx-datasource>
<jndi-name>MySqlDS</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/jbossdb</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name>
<password>root</password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
<!-- should only be used on drivers after 3.22.1 with "ping" support
<valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
-->
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
-->
<!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
-->

<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml -->
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>

</pre>
</blockquote>


Please Help!!!
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 268
Please Help !!!
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


<property name="hibernate.connection.datasource">java:MySqlDS</property>
<property name="hibernate.session_factory_name">java:hibernate/SessionFactory/Siddharth</property>

Those JNDI values look suspect. Shouldn't they start "java:/"?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 268
Even with java:/ it is not working.....
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Originally posted by Siddharth Bhargava:
Even with java:/ it is not working.....


What error message are you seeing? Look back through the log to make sure the DataSource is properly configured. Just telling us it is not working doesn't allow us to offer much advice. How is it "not working"?
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 268
JBoss console doesn't shows anything. It just displays the following thing in the console....


17:58:56,493 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=ConnectionFactoryBinding,name=JmsXA' to JNDI name 'java:JmsXA'
17:58:56,618 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=MySqlDS' to JNDI name 'java:MySqlDS'
17:58:56,712 INFO [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=.../deploy/jmx-console.war/
17:58:57,181 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8080
17:58:57,212 INFO [AjpProtocol] Starting Coyote AJP/1.3 on ajp-127.0.0.1-8009
17:58:57,212 INFO [Server] JBoss (MX MicroKernel) [4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)] Started in 29s:172ms




Eclipse shows the following exception on console

Hi....
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Hello
Could not find datasource
Exception in thread "main" java.lang.NullPointerException
at com.example.jndi.SaveExample.main(SaveExample.java:51)




Please Help !!!
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

Are you running JBoss through Eclipse. If not, is it possible that eclipse isn't connecting to the JBoss server and because you run your app through eclipse that would be important.

Can you also post the code for your SaveExample class?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10288
    
168

Siddharth,

By default, the datasources in JBoss are bound to java: namespace and are not visible outside the server JVM (your code in Eclipse runs in its own separate JVM), to remote clients. See this for more details.

And yes, if this still does not solve your issue, then as Mark said, please post the code.


[My Blog] [JavaRanch Journal]
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 268
Hi Mark,
No I am not running JBoss through Eclipse. I am running eclipse separately. Yeah it may be possible that Eclipse isn't connecting to JBoss because everytime it gives Could not find Datasource exception. How could I make them connect to each other. ?

SaveExample
------------




By default, the datasources in JBoss are bound to java: namespace and are not visible outside the server JVM (your code in Eclipse runs in its own separate JVM), to remote clients.

So what's the solution to this if I want to make a JNDI bound SessionFactory and I am running a Java program from Eclipse and Jboss AS app. server in a separate window. Please Help me I am struggling. !!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Could not find datasource !!!