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 !!!
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:
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..
Joined: Feb 23, 2007
Hi All, The code is as follows :
Exception which occurs is :
Its gives exception in session.flush(); statement.
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.
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.