hibernate tomcat

In this section, you will learn about Hibernate datasource configuration in Tomcat.

hibernate tomcat

hibernate tomcat

In this section, you will learn about Hibernate datasource configuration in Tomcat.

For Hibernate datasource configuration in Tomcat, you will need to take care the following things :

  • There will be no change in your hibernate.cfg.xml file.

  • Also the will be no change in web.xml and your <resource-ref> will be same as previous :
  • <resource-ref>
    <description>My DataSource</description>
    <res-ref-name>jdbc/primaryDB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
  • You need to edit context.xml situated inside $CATALINA_HOME/conf directory add the following Resource entry inside <context>:
  • <Resource name="jdbc/primaryDB" auth="Container" type="javax.sql.DataSource"
    maxActive="100" maxIdle="30" maxWait="10000"
    username="yourusername" password="yourpassword" driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/yourdatabase"/>
    
  • The resource name in the context.xml must match your reference name in the web.xml. This configuration tell to Tomcat environments about how to map resources from your deployment descriptor to the context.xml.