Search This Blog

Wednesday, 31 October 2012

Formatting code using Eclipse

We all write code. But how many of us write clean well formatted code ? Do we care if our classes are correctly indented ? Does it affect us when our IDE shows tiny yellow warnings? Warnings that scream "unused variable" or "unchecked code" ?

Tuesday, 30 October 2012

The wrong result when using fetch and DISTINCT keywords

Consider a query to fetch all entities who have a child with id 1.
public static void testQuerySingleE() {
    final Session session = sessionFactory.openSession();  
    Transaction transaction = session.beginTransaction();

Saturday, 27 October 2012

HQL and the new keyword

It often happens that for a particular use case we need columns from several different tables. Consider the case where we would like the Entity name and its Master Name to be displayed.

Thursday, 25 October 2012

Theta Style Joins

Consider the below queries to find all children of an entity:
public static void testGetEntityChild() {
    final Session session = sessionFactory.openSession();

Wednesday, 24 October 2012

Querying and Outer Joins

In the previous post we saw HQL 's support for inner joins. With inner joins, a rows is returned when there is at least one row from both tables that matches the join condition. However it may be needed that rows are returned even when there are no matches through the join criteria.

Saturday, 20 October 2012

Quering and Inner joins

In the rich object model that Hibernate provides us, it allows us to create object associations. These associations which represent records in other tables would be a weak functionality if there was no query support for them.

Wednesday, 17 October 2012

HQL functions - more of them

In the previous post we saw some common HQL functions. I decided to explore them some more.

Tuesday, 16 October 2012

HQL functions

HQL has the ability to use functions in the WHERE clause.There are the JPA defined functions and also additional HQL functions available for use:

Sunday, 14 October 2012

HQL - The where clause - 2

Continuing from the previous post, I decided to try out other HQL queries

Thursday, 11 October 2012

Attributes in Spring's @Transactional Annotation

In the previous few posts we saw how to use Spring's transaction management.We saw declarative and programmatic support of transactions in Spring. In case of Spring's declarative transaction management using annotations, there are five main attributes that matter:

Monday, 8 October 2012

Caching binary content coming from databases

I recently had the opportunity to work on a mobile project where I faced a whole set of different challenges. All my previous experience involved developing server applications for the web. So when I had to write a REST based API for mobile application we were faced with some interesting challenges.

Spring's @Transactional annotation

Up till now we have seen various ways to achieve transactional behavior in Spring. We saw
Now to do things the easiest way - using annotations.
Since version 2.0 Spring came up with annotations to manage declarative transactions. I decided to use JDBC to test out the annotations.

Friday, 5 October 2012

Programattic Transactions

In the previous post we saw how Spring allows us to use advices for transaction management. However Spring also provides support for programatically managing transactions.

Thursday, 4 October 2012


We saw in our earlier posts how working with TransactionProxyFactoryBean resulted in large configuration files. Even with the abstract bean technique we still are dealing with verbose configuration. As of version 2.0. Spring has come up with using advises to manage transactions.

Monday, 1 October 2012

Managing Transactions the Spring way 2

In the previous post we saw how to use TransactionProxyFactoryBean. For every class that needs transactional behavior, we need to add one such bean that will act as the proxy. For a big application this is a lot of xml definition. The Spring In Action book shows how this code can be reduced  by using abstract beans.