Pritish Kumar Halder is also well-versed as Pk Halder to the world of Information Technology. He has been in technology and software languages for more than twenty years. In this blog post, he shares his experience working with software like Hibernate and Tomcat.
This is how the Tomcat/Hibernate/database environment functions. This is based on a message sent to the email group for Tomcat Users. I’ll go through both Tomcat-managed and Hibernate-managed database connection pooling. While creating thoughts and testing ideas, the following two settings are commonly used.
- Component
- Version
It is advised to utilize the Hibernate Tutorial to walk through the two settings. Database pooling is not used at all in the original tutorial. The tutorial will be modified in the following sections to use either the C3P0 database pooling offered by Hibernate or the JNDI database pooling supplied by Tomcat.
Hibernate Groundwork
Go through or download the Hibernate Tutorial before continuing. This will guarantee that the project is set up appropriately for simple adjustments.
Basics of Tomcat JNDI Database Pooling
Tomcat Preparation
It is necessary to keep mysql-connector-java-5.1.11-bin.jar in Tomcat’s lib directory following the guidelines. By doing this, Tomcat can access the JDBC driver, enabling database pooling. Tomcat’s lib directory shouldn’t contain any Hibernate jar files.
Web Application Working
- The WEB-INF/lib directory holds all Hibernate jar files. No jar files need to be transferred because NetBeans creates the war file appropriately. The context.xml file in META-INF is produced according to the Tomcat instructions.
- The proper username and password should be used instead of the asterisks. Change the database URL to the one that corresponds to your database. You need to add the following lines to WEB-INF/web.xml.
- This setting is entirely boilerplate and is described on the Tomcat documentation website. Please remember that the resource node’s name property in the context.xml file must match the res-ref-name in web.xml.
Hibernate Managed Database Pooling
Relying on database connections controlled by the container. Yet, it operates without a hitch and might be helpful when switching between servlet containers regularly.
Configuration of Hibernate Web Application
- From the context.xml file, remove the Resource>/Resource> tag. Tomcat won’t handle the database connection.
- From the web.xml file, remove the resource-ref>/resource-ref> tag. Tomcat won’t control the database connection.
Hibernate must be set up with that information, as it will handle both the connection and the database pooling. Both connection information and connection pooling information must be contained in hibernate.cfg.xml. These are the files’ excerpts.
Although there may be other settings, this should get everything up and running. Always modify the database settings to meet the needs of your specific application.
Pritish K Halder’s Experience in Web Server
Pritish Kumar Halder has around twenty years of experience working with servlet and web servers like Tomcat and Hibernate. He diversifies his knowledge and skills to other IT professionals in different parts of the world.