Search This Blog

Wednesday, 12 October 2011

Hibernate And Collections Support

Hibernate supports the use of Collections in the Java model objects. Associations between tables are represented using these collections.
e.g.: If there is a one-to-many relation between owner and pet (1 Owner has many pets) then a collection of pets can be mapped in the Owner class.
class Owner {
    private List<Pet> pets = new ArrayList<Pet>();
}

Sunday, 9 October 2011

The Hibernate Inheritance Mechanism - 3 + 4

We saw in approach 3 that a single table is used to represent an entire hierarchy. The end result was a table with sets of unrelated columns, absence of nullability constraints and constantly changing column count on addition of new sub-classes.
In approach 4 we saw how the 3 class hierarchy was split into 3 tables with each class being given a table. Although the resultant schema was a highly normalized schema,  it required joins for fetching records of any of the concrete class and was slightly more complex to implement compared to earlier approaches.
Here we shall modify approach 3 to use approach 4 techniques to come up with a slightly more cleaner implementation for approach 3.

Thursday, 6 October 2011

The Hibernate Inheritance Mechanism - 4

We have seen three of the inheritance techniques as of yet.This is the fourth in the series.
Table per subclass
In this technique a table is created for every class in the hierarchy. There exists a separate table for every interface/abstract class/concrete class that has any persistent properties.
<?xml version="1.0"?>

Monday, 3 October 2011

The Hibernate Inheritance Mechanism - 3

Table per Class Hierarchy:
In this technique an entire class hierarchy is mapped to a single table. Both the Footballer and Cricketer Information will be saved as different rows in the same table.To distinguish the data in each row a discriminator is added.

Saturday, 1 October 2011

The Hibernate Inheritance Mechanism - 2

Table Per Concrete Class + Unions
Continuing with the inheritance mechanisms, I shall now attempt to implement the second approach. This approach tries to overcome the drawbacks of the first technique.
In this technique
  1. The abstract class is also mapped into Hibernate.