What are the advantages of connecting to a database via a JNDI look up
This sounds more like a question about container managed datasources vs locally managed ones
What is the difference between specifying the database properties(drivername,connectionurl,username and password) in hibernate.cfg.xml instead of specifying it as JNDI.
I will assume this was the question you intended to ask and that we are talking about a locally managed datasource. What JNDI allows you to do is centralize your configuration outside of your code. Moving an application to different environments for example would not require a rebuild.
Thanks for your reply. I am aware of what you said on externalizing the configuration resources so that rebuild is not necessary. Is this the only purpose of looking up the datasource via JNDI
How about connection pooling? Like if we deploy our application on jboss. Does Jboss provides default connection pooling mechanism?
In which methodology should we use connection pooling like DBCP or C3po and how?
Joined: Oct 13, 2010
Got the answer for my previous post on difference between specifying the database connection properties within hibernate.cfg.xml and externalizing the connection properties with JNDI look up.
If we are planning to use hibernate on a managed environment(Like deploying on Jboss) then no need to use any pooling mechanism. As application servers provides a default pooling mechanism and this can be achieved by specifying the JNDI look up name in hibernate.cfg.xml
If we are planning to use hibernate on a non managed environment (Like deploying on Tomcat or stand alone applications) then we need to use a pooling mechanism like DBCP or C3P0 which is bundled with hibernate.
Note : we can achieve JNDI look up even with tomcat, where tomcat internally uses DBCP connection pool for managing the connections.
Deploying hibernate applications on tomcat is considered as non managed because of the absence of the transaction manager and JTA.