JPA And Hibernate Many-To-One Tutorial

This is a tutorial to show how to use Java Persistence API (JPA) in a many to one scenario.
The Java Persistence API (JPA), which is part of the Java Enterprise Edition 5 (Java EE 5) EJB 3.0 specification, greatly simplifies Java persistence and provides an object-relational mapping approach that lets you declaratively define how to map Java objects to relational database tables in a standard, portable way that works both inside a Java EE 5 application server and outside an EJB container in a Java Standard Edition 5 (Java SE 5) application. JPA can be used to map your hibernate beans to the proper relational database tables without having to use hibernate mapping xml files.

The completed project, including jars can be found here: Completed Project

Continue reading

Guice Dependency Injection With Struts MVC And Hibernate/Repository Pattern

This is a tutorial on how to use Guice with Struts2 model view controller and Hibernate object relational mapping. This tutorial extends our Guice Dependency Injection With Struts MVC tutorial. The extension adds Hibernate ORM capabilites mediated by Guice to the previous project and takes advantage of the Repository Pattern.

Continue reading

Guice Dependency Injection With Struts MVC

This tutorial will show you how to use Google Guice. Guice (pronounced “juice”) is a lightweight dependency injection framework brought to you by Google. Dependency injection is a design pattern in object-oriented computer programming whose purpose is to reduce the coupling between software components. It is similar to the factory method pattern. Frequently an object uses (depends on) work produced by another part of the system. With DI, the object does not need to know in advance about how the other part of the system works. Instead, the programmer provides (injects) the relevant system component in advance along with a contract that it will behave in a certain way.

Continue reading

Java Architecture For Xml Binding

Java Architecture For Xml Binding is a Java API for taking an xml file, and loading, or “Unmarshalling”, its data into
a set of objects. You would then use those objects in your application for whatever purposes you need them for.
Conversely, you can create a set of objects that represent the parent child relationships in an xml document, load them with the data and do what is called Marshalling, which is then using the JAXB framework to transform those loaded objects into a loaded xml document.

Continue reading

Repository Pattern Using Guice IoC

This is an abstract generic class that is used in conjunction with Hibernate to access database information
using the Repository Pattern.

A repository mediates between the domain and the client. Client objects call upon the Repository to collect the data from and submit the data to the domain. The Repository carries out the appropriate CRUD operations behind the scene, in an encapsulated manner. The pattern also allows the separation between the domain and data mapping layers.

The repository pattern shown here uses Java Hibernate Object Relational Mapping for all the CRUD operations. The Repository uses a Hibernate utility for access to the Hibernate sessions. Access to the hibernateutil is wrapped through the hibernate connection class which is created in a connectionprovider as a singleton using Google Guice Inversion of Control framework.

Continue reading