• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Could not find datasource !!!

 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !!!
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

<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
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please Help !!!
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


<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:/"?
 
Siddharth Bhargava
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even with java:/ it is not working.....
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !!!
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Siddharth Bhargava
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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. !!!
reply
    Bookmark Topic Watch Topic
  • New Topic