• 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

Doubt in using JNDI with Hibernate.

 
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 explain me how to use JNDI as a data source provider if I use JBoss as an application server with Hibernate application. Please explain with a hibernate.cfg.xml file example and also what all do we have to do in JBoss application server. I tried with a simple example but it says that data source not found.. Please Help me !!!
 
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
A similar post was answered at hibernate.org:

JNDI and Hibernate Session Question

Well, it's a great idea to bind a Hibernate Session to you JNDI (Java Naming and Directory Interface) server. This way, rather than having to maintain the Session yourself, the JNDI server will, and that resource can then be accessed by any resource that has access and the rights to do a JNDI lookup.

Here you can see it in a sample hibernate.cfg.xml file.

This was loosely stolen from Chapter 3 of the Hibernate documentation. Look it up for more details:

Free Hibernate Documentation for People to Use to Learn Things About Hibernate


[ July 08, 2008: Message edited by: Cameron Wallace 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 mapping with hibernate.cfg.xml like this only , but it said that datasource not found. What could be the cause of this error. I had a file by the name of MySQL-ds.xml in JBoss\server\default\deploy. Please do help me..
 
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 All,
The code is as follows :



hibernate.cfg.xml



Exception which occurs is :



Its gives exception in session.flush(); statement.

mysql-ds.xml contents



mysql-ds.xml is in deploy directory of JBoss. and JBoss shows


09:09:43,661 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=MySqlDS' to JNDI name 'java:MySqlDS'



Please help. !!! Any help will be greatly appreciated.
Thanks in advance.
 
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

Could not find datasource
Exception in thread "main" java.lang.NullPointerException
at com.example.jndi.SaveExample.main(SaveExample.java:50)



Are you doing this lookup from a standalone java client? By default, the datasources in JBoss are bound to java: namespace and are not visible outside the server JVM, to remote clients. See this for more details.
 
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
Yeah I am doing this lookup from a standalone Java Client program.
 
Cameron Wallace McKenzie
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
When running stand-along code that access J2EE resource, you need to ensure that you are running from a J2EE client container, otherwise, the various enterprise resources will not be available to you.

-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,
How can I do this. Please do explain me. I am trying out a simple standalone application using Eclipse. Thanks in advance.
 
reply
    Bookmark Topic Watch Topic
  • New Topic