{"id":863,"date":"2022-07-02T01:57:46","date_gmt":"2023-06-18T02:17:38","guid":{"rendered":"https:\/\/www.silicloud.com\/blog\/uncategorized\/tutorial-on-how-to-set-up-a-hibernate-tomcat-jndi-datasource\/"},"modified":"2024-03-03T04:29:04","modified_gmt":"2024-03-03T04:29:04","slug":"tutorial-on-hibernate-tomcat-jndi-datasource","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/blog\/tutorial-on-hibernate-tomcat-jndi-datasource\/","title":{"rendered":"Tutorial on how to set up a Hibernate Tomcat JNDI DataSource."},"content":{"rendered":"<p>Hello and welcome to the tutorial on the usage of Hibernate Tomcat JNDI DataSource. Previously, we explored how to utilize Hibernate ORM tool in a standalone java application. Today, we will discover how to incorporate Hibernate with DataSource in the Tomcat servlet container. Implementing Hibernate in a web application is simple. We only need to configure the DataSource properties in the hibernate configuration file. Before anything else, it is necessary to establish a test database and JNDI DataSource in the Tomcat container.<\/p>\n<h3>Database setup for Hibernate&#8217;s DataSource JNDI example.<\/h3>\n<p>I am currently utilizing MySQL for my example. The below script is executed in order to create a basic table and insert certain values into it. The filename of the script is employee.sql.<\/p>\n<pre class=\"post-pre\"><code>CREATE TABLE `Employee` (\r\n  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\r\n  `name` varchar(20) DEFAULT NULL,\r\n  `role` varchar(20) DEFAULT NULL,\r\n  `insert_time` datetime DEFAULT NULL,\r\n  PRIMARY KEY (`id`)\r\n) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8;\r\n\r\nINSERT INTO `Employee` (`id`, `name`, `role`, `insert_time`)\r\nVALUES\r\n\t(3, 'Pankaj', 'CEO', now());\r\nINSERT INTO `Employee` (`id`, `name`, `role`, `insert_time`)\r\nVALUES\r\n\t(14, 'David', 'Developer', now());\r\n<\/code><\/pre>\n<p>The name of the Database schema is TestDB.<\/p>\n<h3>How to configure a DataSource for Tomcat using JNDI?<\/h3>\n<p>In order to set up the Tomcat container to initialize the DataSource, modifications are required in both the server.xml and context.xml files of Tomcat.<\/p>\n<pre class=\"post-pre\"><code>&lt;Resource name=\"jdbc\/MyLocalDB\" \r\n      global=\"jdbc\/MyLocalDB\" \r\n      auth=\"Container\" \r\n      type=\"javax.sql.DataSource\" \r\n      driverClassName=\"com.mysql.jdbc.Driver\" \r\n      url=\"jdbc:mysql:\/\/localhost:3306\/TestDB\" \r\n      username=\"scdev\" \r\n      password=\"scdev123\" \r\n      \r\n      maxActive=\"100\" \r\n      maxIdle=\"20\" \r\n      minIdle=\"5\" \r\n      maxWait=\"10000\"\/&gt;\r\n<\/code><\/pre>\n<p>Include the mentioned resource in the GlobalNamingResources element within the server.xml file, as well as in the context.xml file.<\/p>\n<pre class=\"post-pre\"><code>&lt;ResourceLink name=\"jdbc\/MyLocalDB\"\r\n              global=\"jdbc\/MyLocalDB\"\r\n              auth=\"Container\"\r\n              type=\"javax.sql.DataSource\" \/&gt;\r\n<\/code><\/pre>\n<p>To enable applications to access the JNDI resource named jdbc\/MyLocalDB, you must include the ResourceLink mentioned above in the context.xml file. After restarting the server, there should be no errors in the tomcat server logs. If any configurations are incorrect, such as an incorrect password, the corresponding exception will be displayed in the server log. Additionally, ensure that the MySQL driver jar file is located in the tomcat lib directory. Otherwise, tomcat will be unable to establish a database connection and a ClassNotFoundException will be recorded in the logs. Now that our database and tomcat server JNDI setup is complete, let&#8217;s proceed with creating our web application using hibernate.<\/p>\n<h3>One possible paraphrase of the given phrase could be: &#8220;Dynamic Web Project with a Hibernate DataSource implementation.&#8221;<\/h3>\n<p>In Eclipse, start by creating a dynamic web project and then setting it up as a Maven project. The structure of our final project will resemble the image provided. Keep in mind that we are utilizing Tomcat-7 for deploying our project and have already incorporated it into the build path. This eliminates the necessity to individually add Servlet API dependencies. Since Tomcat-7 supports Servlet 3 specifications, we will utilize annotations for creating our servlets. If you are unfamiliar with the annotations used in Servlet 3, I recommend reviewing the Servlet Tutorial for Beginners. Now, let&#8217;s examine each component individually.<\/p>\n<h3>Maven dependencies for Hibernate.<\/h3>\n<p>This is the appearance of our ultimate pom.xml file.<\/p>\n<pre class=\"post-pre\"><code>&lt;project xmlns=\"https:\/\/maven.apache.org\/POM\/4.0.0\" xmlns:xsi=\"https:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n\txsi:schemaLocation=\"https:\/\/maven.apache.org\/POM\/4.0.0 https:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\"&gt;\r\n\t&lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\r\n\t&lt;groupId&gt;HibernateDataSource&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;HibernateDataSource&lt;\/artifactId&gt;\r\n\t&lt;version&gt;0.0.1-SNAPSHOT&lt;\/version&gt;\r\n\t&lt;packaging&gt;war&lt;\/packaging&gt;\r\n\t\r\n\t&lt;dependencies&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.hibernate&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;hibernate-core&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;4.3.5.Final&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;mysql&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;mysql-connector-java&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;5.0.5&lt;\/version&gt;\r\n\t\t\t&lt;scope&gt;provided&lt;\/scope&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\t&lt;\/dependencies&gt;\r\n\t&lt;build&gt;\r\n\t\t&lt;plugins&gt;\r\n\t\t\t&lt;plugin&gt;\r\n\t\t\t\t&lt;artifactId&gt;maven-war-plugin&lt;\/artifactId&gt;\r\n\t\t\t\t&lt;version&gt;2.3&lt;\/version&gt;\r\n\t\t\t\t&lt;configuration&gt;\r\n\t\t\t\t\t&lt;warSourceDirectory&gt;WebContent&lt;\/warSourceDirectory&gt;\r\n\t\t\t\t\t&lt;failOnMissingWebXml&gt;false&lt;\/failOnMissingWebXml&gt;\r\n\t\t\t\t&lt;\/configuration&gt;\r\n\t\t\t&lt;\/plugin&gt;\r\n\t\t\t&lt;plugin&gt;\r\n\t\t\t\t&lt;artifactId&gt;maven-compiler-plugin&lt;\/artifactId&gt;\r\n\t\t\t\t&lt;version&gt;3.1&lt;\/version&gt;\r\n\t\t\t\t&lt;configuration&gt;\r\n\t\t\t\t\t&lt;source&gt;1.7&lt;\/source&gt;\r\n\t\t\t\t\t&lt;target&gt;1.7&lt;\/target&gt;\r\n\t\t\t\t&lt;\/configuration&gt;\r\n\t\t\t&lt;\/plugin&gt;\r\n\t\t&lt;\/plugins&gt;\r\n\t\t&lt;finalName&gt;${project.artifactId}&lt;\/finalName&gt;\r\n\t&lt;\/build&gt;\r\n&lt;\/project&gt;\r\n<\/code><\/pre>\n<p>I am currently utilizing the most recent version of Hibernate, which is 4.3.5.Final. The hibernate-core dependency has been added for Hibernate. In addition, we have included the mysql-connector-java dependency because we are using a MySQL database. Although the scope is provided since it is already included in the tomcat container libraries, it is recommended to include it. This way, when someone reviews the project dependencies, it will be evident that we are using a MySQL database.<\/p>\n<h3>Configuration of the DataSource in Hibernate.<\/h3>\n<p>Below is the appearance of our hibernate configuration file including the datasource, hibernate.cfg.xml.<\/p>\n<pre class=\"post-pre\"><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;!DOCTYPE hibernate-configuration PUBLIC\r\n\t\t\"-\/\/Hibernate\/Hibernate Configuration DTD 3.0\/\/EN\"\r\n\t\t\"https:\/\/hibernate.org\/dtd\/hibernate-configuration-3.0.dtd\"&gt;\r\n&lt;hibernate-configuration&gt;\r\n    &lt;session-factory&gt;\r\n        &lt;property name=\"hibernate.connection.driver_class\"&gt;com.mysql.jdbc.Driver&lt;\/property&gt;\r\n        &lt;property name=\"hibernate.dialect\"&gt;org.hibernate.dialect.MySQLDialect&lt;\/property&gt;\r\n        &lt;property name=\"hibernate.connection.datasource\"&gt;java:comp\/env\/jdbc\/MyLocalDB&lt;\/property&gt;\r\n        &lt;property name=\"hibernate.current_session_context_class\"&gt;thread&lt;\/property&gt;\r\n        \r\n        &lt;!-- Mapping with model class containing annotations --&gt;\r\n\t&lt;mapping class=\"com.scdev.servlet.hibernate.model.Employee\"\/&gt;\r\n    &lt;\/session-factory&gt;\r\n&lt;\/hibernate-configuration&gt;\r\n<\/code><\/pre>\n<p>The hibernate.connection.datasource property is utilized to specify the name of the DataSource that Hibernate will use for performing database tasks.<\/p>\n<h3>Model Class Example for DataSource in Hibernate<\/h3>\n<p>The model class Employee is utilizing annotations, which can be observed in the hibernate configuration file. Here is an example of how our model bean looks: Employee.java.<\/p>\n<pre class=\"post-pre\"><code>package com.scdev.servlet.hibernate.model;\r\n\r\nimport java.util.Date;\r\n\r\nimport javax.persistence.Column;\r\nimport javax.persistence.Entity;\r\nimport javax.persistence.GeneratedValue;\r\nimport javax.persistence.GenerationType;\r\nimport javax.persistence.Id;\r\nimport javax.persistence.Table;\r\nimport javax.persistence.UniqueConstraint;\r\n\r\n@Entity\r\n@Table(name=\"Employee\", \r\n\t   uniqueConstraints={@UniqueConstraint(columnNames={\"ID\"})})\r\npublic class Employee {\r\n\r\n\t@Id\r\n\t@GeneratedValue(strategy=GenerationType.IDENTITY)\r\n\t@Column(name=\"ID\", nullable=false, unique=true, length=11)\r\n\tprivate int id;\r\n\t\r\n\t@Column(name=\"NAME\", length=20, nullable=true)\r\n\tprivate String name;\r\n\t\r\n\t@Column(name=\"ROLE\", length=20, nullable=true)\r\n\tprivate String role;\r\n\t\r\n\t@Column(name=\"insert_time\", nullable=true)\r\n\tprivate Date insertTime;\r\n\t\r\n\tpublic int getId() {\r\n\t\treturn id;\r\n\t}\r\n\tpublic void setId(int id) {\r\n\t\tthis.id = id;\r\n\t}\r\n\tpublic String getName() {\r\n\t\treturn name;\r\n\t}\r\n\tpublic void setName(String name) {\r\n\t\tthis.name = name;\r\n\t}\r\n\tpublic String getRole() {\r\n\t\treturn role;\r\n\t}\r\n\tpublic void setRole(String role) {\r\n\t\tthis.role = role;\r\n\t}\r\n\tpublic Date getInsertTime() {\r\n\t\treturn insertTime;\r\n\t}\r\n\tpublic void setInsertTime(Date insertTime) {\r\n\t\tthis.insertTime = insertTime;\r\n\t}\r\n}\r\n<\/code><\/pre>\n<p>If you&#8217;re confused about any of the annotations used, you should take a look at the Model bean we used in the Hibernate Beginners Tutorial.<\/p>\n<h3>Using Hibernate with a DataSource and Tomcat&#8217;s JNDI Servlet Listener.<\/h3>\n<p>In order to utilize and handle the Hibernate SessionFactory effectively in the application, which includes both during the usage and destruction of the web application, it is necessary to initialize and destroy the SessionFactory appropriately. Thus, the ideal location to accomplish this is by implementing the HibernateSessionFactoryListener in the ServletContextListener implementation.<\/p>\n<pre class=\"post-pre\"><code>package com.scdev.servlet.hibernate.listener;\r\n\r\nimport javax.servlet.ServletContextEvent;\r\nimport javax.servlet.ServletContextListener;\r\nimport javax.servlet.annotation.WebListener;\r\n\r\nimport org.hibernate.SessionFactory;\r\nimport org.hibernate.boot.registry.StandardServiceRegistryBuilder;\r\nimport org.hibernate.cfg.Configuration;\r\nimport org.hibernate.service.ServiceRegistry;\r\nimport org.jboss.logging.Logger;\r\n\r\n@WebListener\r\npublic class HibernateSessionFactoryListener implements ServletContextListener {\r\n\r\n\tpublic final Logger logger = Logger.getLogger(HibernateSessionFactoryListener.class);\r\n\t\r\n    public void contextDestroyed(ServletContextEvent servletContextEvent) {\r\n    \tSessionFactory sessionFactory = (SessionFactory) servletContextEvent.getServletContext().getAttribute(\"SessionFactory\");\r\n    \tif(sessionFactory != null &amp;&amp; !sessionFactory.isClosed()){\r\n    \t\tlogger.info(\"Closing sessionFactory\");\r\n    \t\tsessionFactory.close();\r\n    \t}\r\n    \tlogger.info(\"Released Hibernate sessionFactory resource\");\r\n    }\r\n\r\n    public void contextInitialized(ServletContextEvent servletContextEvent) {\r\n    \tConfiguration configuration = new Configuration();\r\n    \tconfiguration.configure(\"hibernate.cfg.xml\");\r\n    \tlogger.info(\"Hibernate Configuration created successfully\");\r\n    \t\r\n    \tServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();\r\n    \tlogger.info(\"ServiceRegistry created successfully\");\r\n    \tSessionFactory sessionFactory = configuration\r\n\t\t\t\t.buildSessionFactory(serviceRegistry);\r\n    \tlogger.info(\"SessionFactory created successfully\");\r\n    \t\r\n    \tservletContextEvent.getServletContext().setAttribute(\"SessionFactory\", sessionFactory);\r\n    \tlogger.info(\"Hibernate SessionFactory Configured successfully\");\r\n    }\r\n\t\r\n}\r\n<\/code><\/pre>\n<p>If you are not acquainted with servlet listeners, I recommend reading the Servlet Listener Tutorial.<\/p>\n<h3>Example of implementing a servlet using Hibernate with Tomcat and JNDI.<\/h3>\n<p>We will create a basic servlet that takes the employee ID as a request parameter and displays the employee&#8217;s information from the database. To retrieve the information, we will utilize Hibernate. The servlet will be named GetEmployeeByID.java.<\/p>\n<pre class=\"post-pre\"><code>package com.scdev.servlet.hibernate;\r\n\r\nimport java.io.IOException;\r\nimport java.io.PrintWriter;\r\n\r\nimport javax.servlet.ServletException;\r\nimport javax.servlet.annotation.WebServlet;\r\nimport javax.servlet.http.HttpServlet;\r\nimport javax.servlet.http.HttpServletRequest;\r\nimport javax.servlet.http.HttpServletResponse;\r\n\r\nimport org.hibernate.Session;\r\nimport org.hibernate.SessionFactory;\r\nimport org.hibernate.Transaction;\r\nimport org.jboss.logging.Logger;\r\n\r\nimport com.scdev.servlet.hibernate.model.Employee;\r\n\r\n@WebServlet(\"\/GetEmployeeByID\")\r\npublic class GetEmployeeByID extends HttpServlet {\r\n\tprivate static final long serialVersionUID = 1L;\r\n\t\r\n\tpublic final Logger logger = Logger.getLogger(GetEmployeeByID.class);\r\n       \r\n\tprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {\r\n\t\tint empId = Integer.parseInt(request.getParameter(\"empId\"));\r\n\t\tlogger.info(\"Request Param empId=\"+empId);\r\n\t\t\r\n\t\tSessionFactory sessionFactory = (SessionFactory) request.getServletContext().getAttribute(\"SessionFactory\");\r\n\t\t\r\n\t\tSession session = sessionFactory.getCurrentSession();\r\n\t\tTransaction tx = session.beginTransaction();\r\n\t\tEmployee emp = (Employee) session.get(Employee.class, empId);\r\n\t\ttx.commit();\r\n\t\tPrintWriter out = response.getWriter();\r\n        response.setContentType(\"text\/html\");\r\n        if(emp != null){\r\n        out.print(\"&lt;html&gt;&lt;body&gt;&lt;h2&gt;Employee Details&lt;\/h2&gt;\");\r\n        out.print(\"&lt;table border=\\\"1\\\" cellspacing=10 cellpadding=5&gt;\");\r\n        out.print(\"&lt;th&gt;Employee ID&lt;\/th&gt;\");\r\n        out.print(\"&lt;th&gt;Employee Name&lt;\/th&gt;\");\r\n        out.print(\"&lt;th&gt;Employee Role&lt;\/th&gt;\");\r\n        \r\n            out.print(\"&lt;tr&gt;\");\r\n            out.print(\"&lt;td&gt;\" + empId + \"&lt;\/td&gt;\");\r\n            out.print(\"&lt;td&gt;\" + emp.getName() + \"&lt;\/td&gt;\");\r\n            out.print(\"&lt;td&gt;\" + emp.getRole() + \"&lt;\/td&gt;\");\r\n            out.print(\"&lt;\/tr&gt;\");\r\n        out.print(\"&lt;\/table&gt;&lt;\/body&gt;&lt;br\/&gt;\");\r\n        \r\n        out.print(\"&lt;\/html&gt;\");\r\n        }else{\r\n        \tout.print(\"&lt;html&gt;&lt;body&gt;&lt;h2&gt;No Employee Found with ID=\"+empId+\"&lt;\/h2&gt;&lt;\/body&gt;&lt;\/html&gt;\");\r\n        }\r\n\t}\r\n\r\n}\r\n<\/code><\/pre>\n<p>I have a straightforward servlet class, where I use the @WebServlet annotation to specify the URI pattern for it.<\/p>\n<h3>An application that demonstrates the usage of Hibernate DataSource Tomcat JNDI is being tested.<\/h3>\n<p>Our application is now prepared and can be exported as a war file and deployed in the tomcat container. Here are a few screenshots of our application servlet in action. Please note that the empId request parameter is being passed in the request URL query string. Additionally, you will be able to view our application&#8217;s generated logs in the server logs.<\/p>\n<pre class=\"post-pre\"><code>May 08, 2014 8:14:16 PM org.hibernate.cfg.Configuration configure\r\nINFO: HHH000043: Configuring from resource: hibernate.cfg.xml\r\nMay 08, 2014 8:14:16 PM org.hibernate.cfg.Configuration getConfigurationInputStream\r\nINFO: HHH000040: Configuration resource: hibernate.cfg.xml\r\nMay 08, 2014 8:14:16 PM org.hibernate.cfg.Configuration doConfigure\r\nINFO: HHH000041: Configured SessionFactory: null\r\nMay 08, 2014 8:14:16 PM com.scdev.servlet.hibernate.listener.HibernateSessionFactoryListener contextInitialized\r\nINFO: Hibernate Configuration created successfully\r\nMay 08, 2014 8:14:16 PM com.scdev.servlet.hibernate.listener.HibernateSessionFactoryListener contextInitialized\r\nINFO: ServiceRegistry created successfully\r\nMay 08, 2014 8:14:16 PM org.hibernate.dialect.Dialect &lt;init&gt;\r\nINFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect\r\nMay 08, 2014 8:14:17 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation\r\nINFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4\r\nMay 08, 2014 8:14:17 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService\r\nINFO: HHH000399: Using default transaction strategy (direct JDBC transactions)\r\nMay 08, 2014 8:14:17 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory &lt;init&gt;\r\nINFO: HHH000397: Using ASTQueryTranslatorFactory\r\nMay 08, 2014 8:14:17 PM com.scdev.servlet.hibernate.listener.HibernateSessionFactoryListener contextInitialized\r\nINFO: SessionFactory created successfully\r\nMay 08, 2014 8:14:17 PM com.scdev.servlet.hibernate.listener.HibernateSessionFactoryListener contextInitialized\r\nINFO: Hibernate SessionFactory Configured successfully\r\nMay 08, 2014 8:14:32 PM com.scdev.servlet.hibernate.GetEmployeeByID doGet\r\nINFO: Request Param empId=3\r\nMay 08, 2014 8:15:22 PM com.scdev.servlet.hibernate.GetEmployeeByID doGet\r\nINFO: Request Param empId=3\r\n<\/code><\/pre>\n<p>If you choose to undeploy the application or halt the server, the server logs will display the destruction of the SessionFactory.<\/p>\n<pre class=\"post-pre\"><code>May 08, 2014 11:31:16 PM com.scdev.servlet.hibernate.listener.HibernateSessionFactoryListener contextDestroyed\r\nINFO: Closing sessionFactory\r\nMay 08, 2014 11:31:16 PM com.scdev.servlet.hibernate.listener.HibernateSessionFactoryListener contextDestroyed\r\nINFO: Released Hibernate sessionFactory resource\r\n<\/code><\/pre>\n<p>That concludes the Hibernate DataSource example for the tomcat container. I hope it is easy to comprehend and execute. Feel free to download the sample project using the link provided below and experiment with it to gain further knowledge.<\/p>\n<p>Please retrieve the Hibernate DataSource Project for downloading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello and welcome to the tutorial on the usage of Hibernate Tomcat JNDI DataSource. Previously, we explored how to utilize Hibernate ORM tool in a standalone java application. Today, we will discover how to incorporate Hibernate with DataSource in the Tomcat servlet container. Implementing Hibernate in a web application is simple. We only need to [&hellip;]<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-863","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Tutorial on how to set up a Hibernate Tomcat JNDI DataSource. - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"we will discover how to incorporate Hibernate with Tomcat JNDI DataSource in the Tomcat servlet container.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/blog\/tutorial-on-hibernate-tomcat-jndi-datasource\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Tutorial on how to set up a Hibernate Tomcat JNDI DataSource.\" \/>\n<meta property=\"og:description\" content=\"we will discover how to incorporate Hibernate with Tomcat JNDI DataSource in the Tomcat servlet container.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/blog\/tutorial-on-hibernate-tomcat-jndi-datasource\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-06-18T02:17:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-03T04:29:04+00:00\" \/>\n<meta name=\"author\" content=\"Liam\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Liam\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/tutorial-on-hibernate-tomcat-jndi-datasource\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/tutorial-on-hibernate-tomcat-jndi-datasource\/\"},\"author\":{\"name\":\"Liam\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/23786905eb7b377f45ddb01c17da7671\"},\"headline\":\"Tutorial on how to set up a Hibernate Tomcat JNDI DataSource.\",\"datePublished\":\"2023-06-18T02:17:38+00:00\",\"dateModified\":\"2024-03-03T04:29:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/tutorial-on-hibernate-tomcat-jndi-datasource\/\"},\"wordCount\":910,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/tutorial-on-hibernate-tomcat-jndi-datasource\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/tutorial-on-hibernate-tomcat-jndi-datasource\/\",\"name\":\"Tutorial on how to set up a Hibernate Tomcat JNDI DataSource. - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\"},\"datePublished\":\"2023-06-18T02:17:38+00:00\",\"dateModified\":\"2024-03-03T04:29:04+00:00\",\"description\":\"we will discover how to incorporate Hibernate with Tomcat JNDI DataSource in the Tomcat servlet container.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/tutorial-on-hibernate-tomcat-jndi-datasource\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/blog\/tutorial-on-hibernate-tomcat-jndi-datasource\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/tutorial-on-hibernate-tomcat-jndi-datasource\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.silicloud.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tutorial on how to set up a Hibernate Tomcat JNDI DataSource.\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"name\":\"Silicon Cloud Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\",\"name\":\"Silicon Cloud Blog\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"contentUrl\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"width\":1024,\"height\":1024,\"caption\":\"Silicon Cloud Blog\"},\"image\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\",\"https:\/\/twitter.com\/SiliCloudGlobal\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/23786905eb7b377f45ddb01c17da7671\",\"name\":\"Liam\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8d37ed3e7f770dde8bf069ba0b4298688028c3abaacf1131742fc1352d174ebd?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8d37ed3e7f770dde8bf069ba0b4298688028c3abaacf1131742fc1352d174ebd?s=96&d=mm&r=g\",\"caption\":\"Liam\"},\"sameAs\":[\"http:\/\/Wilson\"],\"url\":\"https:\/\/www.silicloud.com\/blog\/author\/liamwilson\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Tutorial on how to set up a Hibernate Tomcat JNDI DataSource. - Blog - Silicon Cloud","description":"we will discover how to incorporate Hibernate with Tomcat JNDI DataSource in the Tomcat servlet container.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/blog\/tutorial-on-hibernate-tomcat-jndi-datasource\/","og_locale":"en_US","og_type":"article","og_title":"Tutorial on how to set up a Hibernate Tomcat JNDI DataSource.","og_description":"we will discover how to incorporate Hibernate with Tomcat JNDI DataSource in the Tomcat servlet container.","og_url":"https:\/\/www.silicloud.com\/blog\/tutorial-on-hibernate-tomcat-jndi-datasource\/","og_site_name":"Blog - Silicon Cloud","article_publisher":"https:\/\/www.facebook.com\/SiliCloudGlobal\/","article_published_time":"2023-06-18T02:17:38+00:00","article_modified_time":"2024-03-03T04:29:04+00:00","author":"Liam","twitter_card":"summary_large_image","twitter_creator":"@SiliCloudGlobal","twitter_site":"@SiliCloudGlobal","twitter_misc":{"Written by":"Liam","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silicloud.com\/blog\/tutorial-on-hibernate-tomcat-jndi-datasource\/#article","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/tutorial-on-hibernate-tomcat-jndi-datasource\/"},"author":{"name":"Liam","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/23786905eb7b377f45ddb01c17da7671"},"headline":"Tutorial on how to set up a Hibernate Tomcat JNDI DataSource.","datePublished":"2023-06-18T02:17:38+00:00","dateModified":"2024-03-03T04:29:04+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silicloud.com\/blog\/tutorial-on-hibernate-tomcat-jndi-datasource\/"},"wordCount":910,"commentCount":0,"publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/blog\/tutorial-on-hibernate-tomcat-jndi-datasource\/","url":"https:\/\/www.silicloud.com\/blog\/tutorial-on-hibernate-tomcat-jndi-datasource\/","name":"Tutorial on how to set up a Hibernate Tomcat JNDI DataSource. - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/#website"},"datePublished":"2023-06-18T02:17:38+00:00","dateModified":"2024-03-03T04:29:04+00:00","description":"we will discover how to incorporate Hibernate with Tomcat JNDI DataSource in the Tomcat servlet container.","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/blog\/tutorial-on-hibernate-tomcat-jndi-datasource\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/blog\/tutorial-on-hibernate-tomcat-jndi-datasource\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/blog\/tutorial-on-hibernate-tomcat-jndi-datasource\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silicloud.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Tutorial on how to set up a Hibernate Tomcat JNDI DataSource."}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/blog\/#website","url":"https:\/\/www.silicloud.com\/blog\/","name":"Silicon Cloud Blog","description":"","publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.silicloud.com\/blog\/#organization","name":"Silicon Cloud Blog","url":"https:\/\/www.silicloud.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","contentUrl":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","width":1024,"height":1024,"caption":"Silicon Cloud Blog"},"image":{"@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/SiliCloudGlobal\/","https:\/\/twitter.com\/SiliCloudGlobal"]},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/23786905eb7b377f45ddb01c17da7671","name":"Liam","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8d37ed3e7f770dde8bf069ba0b4298688028c3abaacf1131742fc1352d174ebd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8d37ed3e7f770dde8bf069ba0b4298688028c3abaacf1131742fc1352d174ebd?s=96&d=mm&r=g","caption":"Liam"},"sameAs":["http:\/\/Wilson"],"url":"https:\/\/www.silicloud.com\/blog\/author\/liamwilson\/"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/863","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/comments?post=863"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/863\/revisions"}],"predecessor-version":[{"id":1613,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/863\/revisions\/1613"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/media?parent=863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/categories?post=863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/tags?post=863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}