Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Database connectivity

 
vShyam Sundar
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

What is the difference between specifying the database properties(drivername,connectionurl,username and password) in hibernate.cfg.xml instead of specifying it as JNDI.

What are the advantages of connecting to a database via a JNDI look up over specifying the properties in .cfg.xml file



-Shyam.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
vShyam Sundar
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bill

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?


-Shyam.
 
vShyam Sundar
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

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.

Let me know if i am wrong some where

-Shyam.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic