tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Eggers <>
Subject Re: Hibernate in Tomcat
Date Sun, 03 Apr 2011 06:21:50 GMT
----- Original Message start (edited) ----
Hey guys,

I tried to explore a bit the possibility of hibernate in tomcat, but some
things aren't that clear for me.
Before hitting the specific questions, please explain what is hibernate in
Tomcat, when do we want to use it, how do I use it specifically with the
JDBC connection pool (instead of the default DBCP connection pool), and if
misconfiguration of the hibernate can cause disconnections of users on the
application (that uses tomcat).

Now for 2 specific questions, if I may :]
1. in this article, its states that hibernate can be used for managing the
JDBC connection pool, but the strings are for c3p0 pool-
why is that?

2. Do I have to use file, or can I rename it to and still use the content of the hibernate settings?

----- Original Message end (edited) ----

There's an example on how to configure Hibernate and Tomcat on the Tomcat Wiki. 
It's a bit old, but should still be valid.

Hibernate does some nice things, such as making mapping between a relational 
database and objects easier, lazy loading, and loading classes through related 
tables into their proper classes. It also has interfaces to secondary caches 
(default is ehcache), which reduces the need to query a database for read-mostly 

In some of the more complex uses, the Hibernate documents recommend using thread 
local variables and filters to manage Hibernate sessions. This can get a bit 
tricky if you're not careful.

You can do all of this manually with JNDI, some home-grown wrapper classes to 
manage relational-object mapping, and a caching implementation of your choice. 
However, Hibernate (or EclipseLink / JPA 2) makes doing this a bit easier.

Can a misconfigured Hibernate application cause users to be disconnected? 
Usually a misconfigured Hibernate application will refuse to start. Sometimes if 
your resource mapping is incorrect, the application will start, but those 
resources (and queries) will not function.

C3P0 pooling is the one included with Hibernate. Hibernate used to (2.x) include 
an interface to Apache DBCP, but this is no longer available in Hibernate 3.x. 
Thus, all of the pooling examples are written for C3P0.

You can use any file that is found on the classpath. However, the default is 
hibernate.cfg.xml. To change the default, change the following code from:

SessionFactory sf = new Configuration()


SessionFactory sf = new Configuration()

where "catdb.cfg.xml" is the name you've given to the file.

Further Hibernate questions are probably best answered on the Hibernate mailing 
lists or the Hibernate forum.

. . . . just my two cents


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message