Techniques For Integrating Hibernate Into Legacy Java Code – Part 1

If you’re like me, you spend a lot of time dealing with legacy code that, for whatever reason, does not take advantage of modern methodologies and libraries. I’ve taken over Java projects that contain hundreds of thousands of lines of code and not a single third-party jar other than a JDBC driver! One of the most common examples of this is the implementation of the data access layer. These days, the de facto methodology involves Hibernate and DAOs, usually managed by Spring.

This article will detail the steps I recently took to covert a large application from custom-written data access to Hibernate and Spring using the refactoring facilities in Eclipse. The key with this refactorization is to get the existing business logic code (Struts Actions, JSPs, Delegate classes, Business Service classes, etc. ) to access the datastore using Hibernate, managed by Spring, without manually changing any of that code directly. Part 1 will include creating the Hibernate data object classes, DAOs, and refactoring the existing code to work with these newly created types. Part 2 will conclude the project with integration of the Hibernate DAOs and wiring everything up with Spring.

Continue reading “Techniques For Integrating Hibernate Into Legacy Java Code – Part 1”

Use of Hibernate with Java Persistence API

HibernateBefore learning about Persistence technologies, we need to understand what exactly Persistence is in computer science.

Persistence, in simple terms is the ability to retain data structures between various program executions. A perfect example of this would be a word processor saving undo history. In practice, this is achieved by storing the data in non- volatile storage such as a file system or a relational database or an object database.

The popularity of databases has increased manifold in the past few years. Java has become the preferred choice of developers for developing secure, flexible, and scalable database driven web applications. These web applications require objects to be associated with appropriate databases. Hibernate, along with other persistence technologies associate’s objects with the appropriate database in a simple, straight forward and natural way.

Hibernate is one such effort from the Java community to develop many object oriented solutions to data persistence. Any kind of Java persistence solution includes two main elements i.e. ORM (Object Relational Mapping) and OOM (Object Oriented Modeling).

Continue reading “Use of Hibernate with Java Persistence API”