A Comparison Of Persistence Frameworks Computer Science Essay

Published:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

Compare and contrast the following persistence frameworks: Java Persistence API (JPA), Hibernate and Java Database Connectivity. What improvements were made in EJB3.1 and JPA2? Include topics of scalability, security, connection pools, connection factories, entity management, transactional context, query languages, ORM, JCA, JNDI, the DAO-VO design pattern and specifically persistence layer(s) on a distributed n-tier enterprise platform in your discussion.

JPA is an abstraction above JDBC that makes it possible to be independent of SQL.

The main components of JPA are:

ORM: Object relational mapping is a mechanism to map objects to data stored in relational database. JPA uses annotations and/or XML descriptor files to configure the mapping between objects and tables.

CRUD: An entity manager manages lifecycle of JPA entities. It performs database related operations like create, retrieve, update and delete.

JPQL: Java persistence query language allows retrieving data with an object oriented query language.

JTA: Java Transaction API provides transactions and locking mechanisms while accessing data concurrently.

Callbacks and listeners: They hook business logic into the life cycle of a persistent object.

Hibernate is an Object relationship mapping framework. It maps the Java classes to database tables (and from Java data types to SQL data types),

Also provides data query and retrieval facilities

Can significantly reduce development time; otherwise, spent with manual data handling in SQL and JDBC.

Hibernate uses metadata annotations and/or XML descriptor files to configure the mapping between Java objects in the application domain and tables in the relational database.

Hibernate supports inheritance and polymorphism.

Hibernate generates SQL relieves us from manual result set handling and object conversion, and keeps the application portable to all SQL databases.

Hibernate allows to store, fetch, update and delete any kind of objects.

Hibernate allows the development of persistent classes following common Java idiom-including association, inheritance, polymorphism, composition, and the Java collections framework.

Hibernate Query Language (HQL): Hibernate is equipped with an extremely powerful query language that looks very much like SQL. Queries are case-insensitive, except for names of Java classes and properties.

HQL is a language for talking about "sets of objects." It unifies relational operations with object models. It makes SQL be object oriented. It uses classes and properties instead of tables and columns. It supports polymorphism, associations, and is much less verbose than SQL.Other features include: Full support for relational operations, Inner/outer/full joins, cartesian products, Projection, Aggregation (max, avg) and grouping, Ordering, Subqueries, SQL function calls[7]

JDBC is a standard java API for accessing relational database used for persisting state.

It connects to database executes SQL statements and gets result.

JDBC can also be used in a distributed environment.

JDBC API defines the Connection Interface to connect to an underlying data source.

In a typical scenario, a JDBC application will connect to a target data source using one of two mechanisms:

DriverManager -When an application first attempts to connect to a data source by specifying a URL, DriverManager will automatically load any JDBC 4.0 drivers found within the CLASSPATH (any drivers that are pre-JDBC 4.0 must be explicitly loaded by the application).

DataSource - This interface was introduced in the JDBC 2.0 Optional Package API. It is preferred over DriverManager because it allows details about the underlying data source to be transparent to the application.

The JDBC API also defines two important extensions of the DataSource interface to support enterprise applications. These extensions are the following two interfaces:

ConnectionPoolDataSource - supports caching and reusing of physical connections, which improves application performance and scalability. The connection pool names are configured in JNDI.

XADataSource - provides connections that can participate in a distributed transactions.

In persistence architecture based on session beans and JDBC, a session bean delegates all access commands to the JDBC layer.

On receiving a call, the session bean uses JDBC to obtain an object that implements the javax.sql.DataSource interface.

The object returned then serves as a resource manager factory for java.sql.Connection objects (defined by the JDBC API) that implement connections to a database management system.

Once a Connection object has been obtained, the remainder of the persistence code and business logic (queries, updates, stored procedure calls, result set navigation, transaction commit/rollback, and so on) are pure JDBC.

Java applications traditionally used the JDBC (Java Database Connectivity) API to persist data into relational databases.

The JDBC API uses SQL statements to perform create, read, update, and delete (CRUD) operations.

JDBC code is embedded in Java classes -- in other words, it's tightly coupled to the business logic.

This code also relies heavily on SQL, which is not standardized across databases; that makes migrating from one database to another difficult.

By default, JDBC drivers operate in auto-commit mode, where each SQL query/update is an atomic database transaction.

It is straightforward to disable auto-commit, execute several queries/updates, and then explicitly commit the transaction.

DAO-VO

A typical DAO (Data Access object) provides an interface that defines its contract with the outside world. This takes the form of a series of data access and data update methods.

Generally a DAO is defined by means of an interface, whose methods are implemented by entities.

A VO (Value object) is a simple POJO to transfer the data across various tiers of Java acrchitecture.

For each method we retrieve a Persistence Manager, obtain a transaction, and perform our operations. With the use of attach/detach and fetch-groups we can make our persisted objects available outside of the DAO layer in a seamless way

Hibernate and JPA

JPA acts as an adapter over Hibernate. JPA provides the entire API to interact with Hibernate. In a way JPA acts as an abstraction between the java code and Hibernate. In such a architecture it is easy to replace Hibernate if need be.

Java EE Connector Architecture (JCA) is a Java-based technology solution for connecting application servers and enterprise information systems (EIS) as part of enterprise application integration (EAI) solutions. While JDBC is specifically used to connect Java EE applications to databases, JCA is a more generic architecture for connection to legacy systems

What improvements were made in EJB3.1 and JPA2

Improvements in EJB 3.1

With EJB 3.1, there is no need to define home/local interfaces. Now EJB can be defined simple with an annotation.

Singleton beans were introduced with EJB 3.1. Singleton beans can be used for shared data at application level.

Asynchronous EJB calls are now supported with @Asynchronous method-level annotation.

Packaging and deployment can be directly done in a war file.

Session beans with a local view can be accessed without a separate local business interface.

EJB Timer Service enhancements are also included to support cron-like scheduling, deployment-time timer creation, and Stateful Session Bean timed objects.

Embedded container: A new embeddable API is available for executing EJB components within a Java SE environment (for unit testing, batch processing, etc.).

EJB Lite: This definition of a lightweight subset of functionalities can be provided within Java EE Profiles (such as the Java EE Web Profile).

Portable JNDI name: The syntax for looking up EJB components is now specified.

Improvements in JPA 2.0

Collections of basic types.

Collections of embeddable.

Maintaining a persistent ordering is now possible with the @OrderColumn annotation.

Orphan removal that allows removal of child object when parent object is removed.

Pessimistic locking has also been introduced along with optimistic locking.

JPA 2.0 also introduced foreign key mappings for unidirectional one-to-many relationships.

Improved support for maps. Maps can now have keys and values of basic types,

entities, or embeddables.

Criteria query API which allows queries to constructed in an object-oriented manner.

Improvements in JPQL syntax.

Embeddable objects can now be nested into other embeddable objects and have relationships to entities.

The dot (.) navigation syntax has been extended to handle embeddables with relationships and embeddables of embeddables.

Writing Services

Essay Writing
Service

Find out how the very best essay writing service can help you accomplish more and achieve higher marks today.

Assignment Writing Service

From complicated assignments to tricky tasks, our experts can tackle virtually any question thrown at them.

Dissertation Writing Service

A dissertation (also known as a thesis or research project) is probably the most important piece of work for any student! From full dissertations to individual chapters, we’re on hand to support you.

Coursework Writing Service

Our expert qualified writers can help you get your coursework right first time, every time.

Dissertation Proposal Service

The first step to completing a dissertation is to create a proposal that talks about what you wish to do. Our experts can design suitable methodologies - perfect to help you get started with a dissertation.

Report Writing
Service

Reports for any audience. Perfectly structured, professionally written, and tailored to suit your exact requirements.

Essay Skeleton Answer Service

If you’re just looking for some help to get started on an essay, our outline service provides you with a perfect essay plan.

Marking & Proofreading Service

Not sure if your work is hitting the mark? Struggling to get feedback from your lecturer? Our premium marking service was created just for you - get the feedback you deserve now.

Exam Revision
Service

Exams can be one of the most stressful experiences you’ll ever have! Revision is key, and we’re here to help. With custom created revision notes and exam answers, you’ll never feel underprepared again.