File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Database connectivity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Database connectivity" Watch "Database connectivity" New topic
Author

Database connectivity

vShyam Sundar
Ranch Hand

Joined: Oct 13, 2010
Posts: 60
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

Joined: Mar 07, 2010
Posts: 1649
    
    7

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.


[How To Ask Questions][Read before you PM me]
vShyam Sundar
Ranch Hand

Joined: Oct 13, 2010
Posts: 60
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

Joined: Oct 13, 2010
Posts: 60
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Database connectivity