2017-03-07

In this article we will show you how to install Hibernate along with needed packages in Tomcat for the development of Hibernate based web applications. Hibernate is an open source, lightweight, high performance ORM (Object Relational Mapping) tool. In addition and as you may already know, Hibernate is a widely used ORM tool due to its high performance features.

In fact, here at DailyRazor we are an early adaptor of the latest web development technologies. A large number of websites, web applications and web services based on Hibernate framework run optimally on our hosting infrastructure. Therefore, our objective is to show you how to easily install Hibernate on either our Private or Shared Tomcat hosting servers for use in development and deployment of any Java web application .

Install Hibernate Environment in Tomcat

[SPECIAL OFFER]: 15 Days FREE Trial Java Web Hosting

[BENEFITS]:

Host Your Hibernate Web Application for Free!

Private Tomcat Server with Dedicated JVM Heap & PermGen

Custom Java Development Kit (JDK) version

Super Fast Servers with 24/7/365 Technical Support

Click here to access this [SPECIAL OFFER]

Step 1: Create a MySQL Server Database and Database User

First and foremost to install Hibernate, the framework needs a database connection to work with. Therefore, you need to create a database. In this article we are assuming that you have already created database and user with all privileges. Otherwise, log into your control and follow this tutorial to create a MySQL database and database user.

Step 2: Configure Database settings in web application:

Next, before you can deploy your WAR file to the remote Tomcat on our hosting infrastructure, you need to add the remote database connection details in your web application. Presently, for a Hibernate based application connection parameters are stipulated in the hibernate.cfg.xml file. Whereas, in some other Java frameworks like Spring, Spring Boot, etc database connections are stipulated in either applicationContext.xml or application.properties files.

As a result, in this section we are providing some set of properties’ and xml file you can use to configure the database for your application. Kindly contact us at support@dailyrazor.com if you have any problem even after reading this article. Therefore, in the MySQL and SQL Server database related configuration files provided below, you need to change these database parameters with yours as follows:

Replace “database-name” with your database name.

Replace “database-user” with your database user.

Replace “database-password” with your database password.

Sample hibernate.cfg.xml file for MySql

Sample MySql connection application.properties file for Spring Boot framework

[SPECIAL OFFER]: 15 Days FREE Trial Java Web Hosting

[BENEFITS]:

Host Your Hibernate Web Application for Free!

Private Tomcat Server with Dedicated JVM Heap & PermGen

Custom Java Development Kit (JDK) version

Super Fast Servers with 24/7/365 Technical Support

Click here to access this [SPECIAL OFFER]

Sample MySql applicationContext.xml file for Spring framework

[SPECIAL OFFER]: 15 Days FREE Trial Java Web Hosting

[BENEFITS]:

Host Your Hibernate Web Application for Free!

Private Tomcat Server with Dedicated JVM Heap & PermGen

Custom Java Development Kit (JDK) version

Super Fast Servers with 24/7/365 Technical Support

Click here to access this [SPECIAL OFFER]

Sample hibernate.cfg.xml file for SQL Server

Sample SQL Server applicationContext.xml file for Spring framework

[SPECIAL OFFER]: 15 Days FREE Trial Java Web Hosting

[BENEFITS]:

Host Your Hibernate Web Application for Free!

Private Tomcat Server with Dedicated JVM Heap & PermGen

Custom Java Development Kit (JDK) version

Super Fast Servers with 24/7/365 Technical Support

Click here to access this [SPECIAL OFFER]

Step 3: Build your web application again after database configuration:

Once you’ve completed Steps 1 & 2, you need to create a WAR file for your web application. As a matter of fact, best practice recommends you create the WAR file and deploy it locally first of all. In the event you have not performed proper database configuration via the any of the above mentioned files, the WAR file will not deploy properly on your local PC.

Note:In order to connect to a remote database server from your local PC, you should allow remote connection to your database. Here’s a quick guide on how to do this via your hosting server’s control panel.

Step 4: Deploy your web application WAR file using Filezilla:

Once your WAR file is ready and deployed successfully on your local Tomcat installation, go ahead and upload it to our hosting server using an FTP client such as Filezilla.

For instance, in this article we will deploy “HibernateDemoDailyRazor.war” file in Tomcat. It is located at “D:\learning\hibernate-application\HibernateDemoDailyRazor\target\HibernateDemoDailyRazor.war” on our local PC.

Step 4.1 – Open the FTP client on your local PC

Locate the Filezilla application (or any other FTP client you’re using) on your local PC and open it.


Step 4.2 – Login with the login credentials provided to you after your hosting server set up

At this point, you need to enter your FTP information to connect to remote hosting server. For Host we suggest you to enter your server’s IP address. You can also enter your domain name if it’s already pointing to our servers. Once you have provided all the information correctly. Click on Quickconnect icon to access the server.
“Directory listing successful” – This message will appear once Filezilla is successfully connected to the server. Once successfully connected, Filezilla is ready to communicate with the server. After successful connection Filezilla would look like the image below.

NOTE: In Filezilla, the left panel shows folders/directories in your local computer and the right Panel shows your remote host’s folders/directories.

Step 4.3 – Locate the required folders on your local computer and the remote server.

First of all, locate the folder/directory on your local computer where your .war file resides. In our case, we want to deploy “HibernateDemoDailyRazor.war” which is located at “D:\learning\hibernate-application\HibernateDemoDailyRazor\target\HibernateDemoDailyRazor.war” in our local system. As a result, in the left panel of Filezilla, we’ll open “D:\learning\hibernate-application\HibernateDemoDailyRazor\target”.

Next, locate the “webapps” folder/directory on the remote server. We need to upload “HibernateDemoDailyRazor.war” to “/home/privtomc/tomcat/webapps/privatetomcat.readwritebox.com/” So we have opened the directory in right panel of Filezilla.


Step 4.4 : Uploading your .war file or “complete web directory”

Next, please select your .war file in the left panel. Right click and select Upload. See the below image showing the process to upload HibernateDemoDailyRazor.war. It will upload your .war to the selected directory on the remote server.

Note: This same method can be used to upload HibernateDemoDailyRazor directory as well (i.e. if did not park your web application into a WAR file).

At any rate, once the .war has been moved to remote server, it gets extracted automatically if you are using a Private Tomcat server. You can see in the image below HibernateDemoDailyRazor.war has been extracted to HibernateDemoDailyRazor. If you’re using a Shared Tomcat server, you need to request Tomcat restart by emailing support@dailyrazor.com

Step 4.5 : Check your url after successful deployment

In conclusion, we have deployed HibernateDemoDailyRazor.war file. Since our base url is http://PrivateTomcatexamples.dailyrazor.com/ we can find the complete web application at http://PrivateTomcatexamples.dailyrazor.com/HibernateDemoDailyRazor

Advice: Some common problems while deploying Hibernate based web application

java.lang.OutOfMemoryError: GC overhead limit exceeded:

If your war file size is more than 200 MB and you’re trying to deploy WAR via Tomcat Manager application. Please use Filezilla to upload your war file. Deploying war file using Tomcat Manager may cause this error.

java.util.zip.ZipException: error in opening zip file

Restart your Tomcat server to solve this issue.

java.sql.SQLException: Access denied for user ‘someuser’@’localhost’ (using password: YES)

This error occurs if you are using invalid database credentials. Make sure you’re using the correct database credentials. Make sure the database user exists in your remote database server and make sure all privileges are assigned to the user.

Thanks for reading this article. In case you need any help regarding Hibernate framework deployment, please email us at support@dailyrazor.com. We are available 24/7 and very much looking forward to assisting you.

[SPECIAL OFFER]: 15 Days FREE Trial Java Web Hosting

[BENEFITS]:

Host Your Hibernate Web Application for Free!

Private Tomcat Server with Dedicated JVM Heap & PermGen

Custom Java Development Kit (JDK) version

Super Fast Servers with 24/7/365 Technical Support

Click here to access this [SPECIAL OFFER]

The post How to Install Hibernate ORM appeared first on DailyRazor.com.

Show more