Views 
   PDF Download PDF Downloads: 1205

 Open Access -   Download full article: 

Evaluating Performance of Hibernate ORM Based Applications Using HQL Query Optimization

Salahuddin Saddar, Junaid Baloch, Memoona Sami*, Nasrullah Pirzada, Vijdan Khalique and Arsalan Aftab Memon

Mehran University of Engineering and Technology Jamshoro Hyderabad, Pakistan.

Corresponding author Email: memoona.sami@faculty.muet.edu.pk

DOI : http://dx.doi.org/10.13005/ojcst11.02.07

Article Publishing History
Article Received on : 24-4-2018
Article Accepted on : 29-5-2018
Article Published : 29 May 2018
Article Metrics
ABSTRACT:

With the continuous advancement in technology, web technologies have reached to a new height. Enterprise applications are meant to be the basic need of today’s world which aims to produce results that are highly reliable, portable and adaptable. With these enormous features, they needed the storage mechanism which could handle and store the data effectively. The storage system thus required was a database management system but again technical knowledge was required to make things work appropriately.  However, this approach was the traditional one which requires data to be stored in tabular format whereas Object oriented architecture has taken the programming language to a whole new technical phase for which the traditional RDBMS will not efficiently accomplish the expected job. To fulfill this gap in the literature, Object Relational Mapping is emerged as a solution to provide which provide comparative technical features effortlessly. These characteristics simplify and make the mapping of objects in object-oriented programming languages more flexible, efficient and easy to use.Therefore, we propose in this paper that Object relational Modeling (ORM) relates each object of object oriented languages to corresponding rows in the table.

KEYWORDS: Hibernate; HQL; Mapping; ORM; OOP; RDMS

Copy the following to cite this article:

Saddar S, Baloch J, Sami M, Pirzada N, Khalique V, Memon A. A. Evaluating Performance of Hibernate ORM Based Applications Using HQL Query Optimization. Orient.J. Comp. Sci. and Technol;11(2)


Copy the following to cite this URL:

Saddar S, Baloch J, Sami M, Pirzada N, Khalique V, Memon A. A. Evaluating Performance of Hibernate ORM Based Applications Using HQL Query Optimization. Orient. J. Comp. Sci. and Technol;11(2). Available from: http://www.computerscijournal.org/?p=8297


Introduction 

On the temporary basis, filing and spreadsheets is used for storing massive data. However, commonly relational databases are used for the application and its availability. Relational databases require data to be stored in form of tables which is not sufficient. It does not work out with this fast emerging technical world and its needs.  Since, now the time has gone where procedural languages were used. Today is an era of Object oriented programming which considers each and everything as an object and serves better for providing enterprise solutions.

The selection for Java language is justified since it is an open source language and also provides number of facilities such as: an API for querying and manipulating databases commonly termed as Java Database Connectivity (JDBC) API. Along with that, it gives the important transformation of information between the two sorts (JAVA and RDBMS).1

Also, there are number of ORM instruments to play out the activity by coding.

Literature Review

In modern development, Object Relational Mapping such as Hibernate has proved to be a good choice. Due to its portable and easy to use nature, it has been popular.2 Different languages are pooled in a database application for data processing. They proposed a framework to optimized database applications which proves to be a significant solution in real world applications.15 Various factors such as database access and efficiency influence Information management systems. A real case is enlightened to define hibernate ORM mechanisms16. ORM tools are used to map objects to and from relational form. This paper highlights the evaluation performance of open source object persistence.17

Our proposed study examines the ORM tool by performing distinctive tests, in various situations, this examination is centered on a wide assortment of hibernate consideration.  Execution time is the basic measurement tool for it.

It considers numerous situations especially related about one-to-many relation in hibernate.

Correlates object database and ORM tools.

Examines an ORM tool hibernates by performing distinctive investigations, in various situations.

Has pleasantly centered on execution improvements.

Drives attention on number of inquiries executed however following are also significant performance concerns.

ORM v/s Versant Object DB

Versant has more than 50000 users from different fields, like government, medical and telecommunication.

However, hibernate is a standard tool, used for ORM queries. It can be used with a relational database as well as with Oracle Enterprise edition.

Table: 1 Comparison between Hibernate and Versant

Table 1: Comparison between Hibernate and Versant 



Click here to View table

 

A basic investigation was carried out to judge the performance of object database with ORM tools by making use of tools like Versant Object Database Management System (ODBMS) and Hibernate. The comparison between features is shown in table 1.

The main concept behind the speed of hibernate is that the query is carried out on indexed columns of objects which ultimately makes hibernate much faster than versant so it has won this race in terms of performance.Both tools provide java interfaces, sessional control mechanism. Hibernate offers XML support in all cases but versant supports for some cases.

Hibernate v/s JPOX

This study examines the functioning of Hibernate and OpenJPA and JPOX and Speedo.

Diverse sort of tests were carried out that were greatly based upon and data retrieval. The following queries were utilized for execution tests.

To load one object twice within a transaction.

To load a single object two time among these transactions.

Lazy loading an object data.

Eager loading an object data.

Loading and saving similar and complex objects.

Processing time gives the immediate execution consequences and shows performance of ORM or persistence device for a particular test.5

The consequences of the lazy loading were better in the case of the Hibernate and OpenJPA than the JPOX and Speedo.

If the second query is concerned, ORM apparatus performed exceptional. The high hand of caching systems was proved to take place in this regard3.

So finally, it is concluded that hibernate played out the best general in majority of queries however, JDO marked its way in case of eager loading and complex objects.

Hibernate v/s iBatis

Discussions were carried out in which examination of iBatis and Hibernate was embraced. With a specific end goal to play out the correlation, different tests were performed using distinctive exercises on a small banking system. The tests are dependent on a Java program, which utilizes both iBatis and Hibernate.  It performs essential Structured Query Languages (SQL) operations as execution test. These experiments were executed for numerous clients. Java threads were carried out for multi-client tests. To play out the tests the following input sources can be utilized.4

Select continues used tool.

Records which are to be updated at one time

Select the need of performing the entire or one of the operations.

Which threads (users) used to execute the multi user testing.

Which iterations mean the number of the time a particular set has been accessed?

The outcomes demonstrate that Hibernate utilizes much time to embed information because of mapping. Likewise, it was revealed that Hibernate consumes extra time to run out the query for the 1st time then the 2nd time. This is essentially because of the store cache implementation in Hibernate. Hence it is proved; Hibernate performs superior to iBatis in hot queries, while performs slower for cold queries.

Hibernating

Hibernate ORM (Object Relational Model) is a mediator between Java based objects and relational database which shapes the entities into object oriented domain. Hibernation enables malleable access to relational databases with high level object based functions.

The Figure 1 shows the layered architecture of Hibernate, which is used to help the users without knowing APIs.Hibernate uses database and configuration data to deliver services to the applications.

Figure: 1 Structure of hibernating

Figure 1: Structure of hibernating 



Click here to View figure

 

HQL (Hibernate Query Language) and SQL (Structured Query Language) are almost similar. HQL, however, deals with objects and SQL works on tables. To carry out the interactions with relational databases, Hibernate transforms HQL queries into SQL.Not only this, Hibernate is itself capable of executive direct SQL queries. HQL is much preferred in order to avoid database portability issues which can arise in near future.7

HQL Clauses

Keywords such as SELECT, FROM and WHERE and so forth are utilized as Keyword for writing clauses to perform HQL operations.

From Clause

Persistent objects are loaded using the From Clause into the memory. It requires Package and Class names.

AS Clause

In the HQL queries, AS clause is utilized to allocate Aliases to the classes.  This clause proves to be useful to manage long queries. The Aliases can be relegated to the classes specifically.

Select Clause

The select condition empowers the designer to recover specific properties of the items instead of the entire question itself. The Select condition empowers the engineers to apply more control over the choice contrasted with the FROM statement.13

Where Clause

Where provision empowers the engineer to characterize a condition in view of which the properties ought to be recovered, consequently empowering to limit the outcome.

Order by Clause

This statement is used to select the outcomes which are recovered by the inquiry. The requesting/arranging of the outcomes relies upon the boundary gave by the engineer which can either be DESC for descending order or ASC for ascending order.

Update Clause

Engineers may utilize the Update Clause to refresh the properties of an object, the e. With the Hibernate 3, mass updates can be performed. With a specific end goal to execute the update, the execute Update() method is utilized.6

Delete Clause

Delete clause is utilized by the designer to erase at least one object. The erasure of objects works contrastingly by comparing Hibernate 2 and 3. The execute Update() method is utilized for deleting purpose,.

Insert Clause

This clause is utilized to embed new records in HQL.

Object Relatinal Mapping (ORM)

Object Relational Mapping is a strategy that is utilized to bring similarity between the distinctive sorts of information. If an object is stored into data store and converted back to object without changing its properties, it is said to be persistent.8,14

One of the Code bits for this is:-

A case of Office and Employee class is taken as an example.

Figure: 2(a) Office and Employee class code

Figure 2(a): Office and Employee class code 



Click here to View figure

 

Figure: 2(a) JAVA  Office dialect class

Figure: 2(a): JAVA  Office dialect class 



Click here to View figure

 

The above mentioned code in figure 2 (b) isused to create a JAVA  Office dialect class.The @Entity comment performs as an entity class. To generate keys automatically the @id and @Generated Value is utilized they are also used to represent the primary key. @One To One comment gives affiliation the Employee class instances i.e. worker and manager. Additionally the Employee class gives the data to create the employee instance. The code bit in Figure 3 displays how to make object relational mapping between a relational database and a programming dialect like JAVA.

Figure: 3 Object relational mapping between a relational  databaseand a programming dialect like JAVA

Figure 3: Object relational mapping between a relational databaseand a programming dialect like JAVA 

 

Click here to View figure

 

Problems of Data Navigation

Java and relational databases both deal differently in getting to information and navigating or exploring from one object to next.11 The associations can be either unidirectional or bidirectional. Java accesses data by making use of getter methods, e.g., get Name(). However, getting to a particular data in a relational database will require SQL queries which can be complicated much if it requires joins. The performance can only be enhanced if minimum requests are made to database.9

Inheritance Mapping

Mapping of inheritance particularly defined at the object level is the real essence of inheritance mapping. To map a database scheme, three various inheritance techniques are listed out:

Inheritance Mapping to Single Table: Nulls’ Style

A class with its entire sub classes is mapped to a single database table which can possible nullify few attributes in that table. That’s the reason this type of mapping is referred to as Nulls’ style.

Inheritance Mapping to Multiple Style: ER Style

This technique plots a segment to no of tables in the database of the inheritance hierarchy..

Association Mapping

Association is the basic relation or affiliation between the two classes or the collection between the classes.

Three kinds of association mappings are defined below: 

Many-To-One Association

An association L on class M and N is many-to-one if for any object M, is related with at most one object in N.

One-To-One Association

L will be a balanced association, if any object in N is related with at most one object in M.9

Many-To-Many Association

If none of above mentioned condition matches, it falls in the category of many-to-many association.12

Table: 2 HQL Query Optimization

Table 2: HQL Query Optimization 



Click here to View table

 

Table : 3 Fetch type LAZY

Table 3: Fetch type LAZY 



Click here to View table

 

Experiments and Results

Experiment 1

Objective

Fetching Parameter Eager using HQL Query option

FIGURE 4:  FETCH PARAMETER EAGER WITH HQL QUERY OPTION

Figure 4: Fetch Parameter Eager with HQL Query option 



Click here to View figure

 

Result

As the table shows, the normal and the real records are same, using fetch type Eager, Hibernate is expressly characterized to collect entire records along with the accumulations of entire objects.

The time efficiency of these two is portrayed as:

Figure: 5 Time Efficiency of HQL Query and Criteria API

Figure 5: Time Efficiency of HQL Query and Criteria API 



Click here to View figure

 

Experiment 2

Objective

Associated collections are loaded via useless database hit even in the absence of associated object exists at all

FIGURE: 6   USELESS DATABASE HIT TO LOAD ASSOCIATED COLLECTION

Figure 6: Useless Database Hit to load associated collection 



Click here to View figure

 

Result

As a result of Eager search, a considerable measure of queries was characterized by HQL, as the majority of the objects are retrieved in a single run in view of the preparing of extensive number of queries.

Figure 7(a): HQL QUERY JOINS FETCHING Figure: 7 (b) HQL QUERY JOINS FETCHNG THE ASSOCIATED COLLECTIONS

Figure 7(a): HQL query joins fetching Figure: 7 (b) HQL query joins fetchng the associated collections 

 

Click here to View figure

 

Experiment 3

Objective

Associated collections are not fetched by HQL query joins. Extra hits are obligatory to load the association.

Result

As the outcome table displays, the normal queries count are ZERO. But, but it is not real scenario on account of the Fetch type utilized is Eager, as specified above. Which bring about stacking of total objects, in addition to the index and the different gathering of objects?

Desinging Experimental Senarios

The few Test cases scenarios are illustrated below:  Table 2,3,4 shows the test cases.

Benefits

No any master required for database administration.

Avoids superfluous access to databases.

Avoids composing of long queries and joins.

Suitable for an expansive enterprise applications.

Requires no progressions to be made, if databases are changed or the other way around.

Conclusion

There are different techniques for managing transactions implemented by systems that can affect system performances. This research basically focuses on how each system performs when recovering data, that’s all important to focus on factors such as cache management, query language, and ORM functions that have these tools. Similarly, we used different types of searches to check the operation of different systems run. These queries are selected according to different criteria and navigation paths. These questions provide a way to check the different functions of systems, such as their search languages inheritance strategies and their caching mechanisms. These functions can help us decide which The system works better and what needs to be done to improve performance. It is very much clear from the results that utilizing Criteria API rather than conventional HQL Query will furnish result sets with wanted throughput that will upgrade the execution of querying. Moreover, recovering records utilizing LAZY fetch type will give low overhead to applications. A good ORM will automatically generate all the SQL needed to store the objects.

Acknowledgement

We would like to thanks co-authors for the discussion and contributions in provided research.

References

  1. Chen, Tse-Hsun, et al., “An empirical study on the practice of maintaining object-relational mapping code in java systems.” Proceedings of the 13th International Conference on Mining Software Repositories. ACM, 2016.
    CrossRef
  2. Decan, Alexandre, Mathieu Goeminne, and Tom Mens. “On the interaction of relational database access technologies in open source java projects.” arXiv preprint arXiv:1701.00416. 2017.
  3. Dhingra, Neha, Emad Abdel moghith, and Hussein T. Mouftah. “Performance Evaluation of JPA Based ORM Techniques.” In Proceedings of 2nd International Conference on Computer Science Networks and Information Technology. Aug 2016;Held on 27th-28th.
  4. Babu, Chitra, and G. Gunasingh. “DESH: Database evaluation system with hibernate ORM framework.” Advances in Computing, Communications and Informatics (ICACCI), 2016 International Conference on. IEEE, 2016.
  5. Fraczek, Konrad, and Malgorzata Plechawska-Wojcik. “Comparative Analysis of Relational and Non-relational Databases in the Context of Performance in Web Applications.” International Conference: Beyond Databases, Architectures and Structures. Springer, Cham, 2017.
  6. Wan, Jing‐Jing, Zhen Qin, and Xia Liu. “ORM Elevation in Response to Cognitive Impairment Is an Accompanying Phenomenon.” CNS neuroscience & therapeutics. 2016;22:8:723-724.
    CrossRef
  7. Bernstein, Philip A., et al., Incremental mapping compilation in an object-to-relational mapping system (extended version). Technical Report MSR-TR-2013-45, Microsoft Research. 2013.
  8. Chen, Tse-Hsun, et al., “Cache Optimizer: Helping developers configure caching frameworks for Hibernate-based database-centric web applications.” Proceedings of the 2016 24th ACM SIGSOFT International Symposium on Foundations of Software Engineering. ACM. 2016.
    CrossRef
  9. Procaccianti, Giuseppe, Patricia Lago, and Wouter Diesveld. “Energy efficiency of orm approaches: an empirical evaluation.” Proceedings of the 10th ACM/IEEE International Symposium on Empirical Software Engineering and Measurement. ACM. 2016.
    CrossRef
  10. Chen, Tse-Hsun, et al., “Cache Optimizer: Helping developers configure caching frameworks for Hibernate-based database-centric web applications.” Proceedings of the 2016 24th ACM SIGSOFT International Symposium on Foundations of Software Engineering. ACM. 2016.
    CrossRef
  11. Chen, Tse-Hsun, et al., “Detecting problems in the database access code of large scale systems-an industrial experience report.” Software Engineering Companion (ICSE-C), IEEE/ACM International Conference on. IEEE, 2016.
  12. Chen, Tse-Hsun, et al., “An empirical study on the practice of maintaining object-relational mapping code in java systems.” Proceedings of the 13th International Conference on Mining Software Repositories. ACM. 2016.
    CrossRef
  13. Grechanik, Mark, et al., “Enhancing rules for cloud resource provisioning via learned software performance models.” Proceedings of the 7th ACM/SPEC on International Conference on Performance Engineering. ACM. 2016.
  14. Ackermann, Hilmar, et al, “A backend extension mechanism for PQL/Java with free run-time optimisation.” International Conference on Compiler Construction. Springer, Berlin, Heidelberg. 2015.
  15. Emani, K. Venkatesh, and S. Sudarshan. “Cobra: A Framework for Cost Based Rewriting of Database Applications.” arXiv preprint arXiv:1801.04891. 2018.
  16. Zhengju, Chen. “HIBERNATE-BASED DATABASE ACCESS OPTIMIZATION [J].” Computer Applications and Software 7. 2012:045.
  17. Van Zyl, Pieter, Derrick G. Kourie, and Andrew Boake. “Comparing the performance of object databases and ORM tools.” Proceedings of the 2006 annual research conference of the South African institute of computer scientists and information technologists on IT research in developing countries. South African Institute for Computer Scientists and Information Technologists. 2006.
    CrossRef

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.