Search This Blog

Saturday, 29 September 2012

Managing Transactions the Spring way

In the previous post we saw how Spring managed caching via proxies. It follows a similar route to achieve transaction management in a very transparent way. Spring supports programmatic and declarative transactions. Declarative uses aspects and therefore proxies and is therefore achieved in a very transparent manner.

Thursday, 27 September 2012

Caching in Spring-2

In our previous post we saw how to use Spring and  Ehcache. We did that through a lot of XML configuration. Spring also provides us with annotations to use.

Tuesday, 25 September 2012

Caching in Spring

Many a times we come upon the need for using caching in our code to improve performance. In my very first IT project we had done caching by writing our own code involving maps, generics and some get put calls. Now we know about readily available third party cache providers and Spring fortunately provides integration for several of these.

Sunday, 23 September 2012

Managing module dependency versions with Maven

When building a complex application with Maven it is normal to split the code among multiple projects. Every project has its own pom file and we use a parent pom file to build all projects in the process generating our final build or deployment artifact. The problem observed is that the different projects have their own dependencies.

Friday, 21 September 2012

Spring and Hibernate 2

In the previous post we saw the working of the HibernateTemplate. As discussed Spring doesn't need us to work with it. We can now directly work with the SessionFactory.

Thursday, 20 September 2012

Spring and Hibernate

In our earlier post we saw how Spring can be integrated with JDBC. Spring also provides a similar template class for use with Hibernate - org.springframework.orm.hibernate3.HibernateTemplate.

Wednesday, 19 September 2012

String Pool and SLF4J

A few days back we had a code review and one of the concerns raised was "too many logs".
The statement made was : Too many logs in code result could in memory issues.
This was the first time somebody had come with such a feedback. Most of the time it was absence of logs that was the common concern. I decided to spend some time analyzing the complaint.

Saturday, 15 September 2012

HQL - The where clause

Logic in applications almost always involves execution of queries involving where clauses on the database. HQL also supports where clauses.

Friday, 14 September 2012

HQL - Getting all the records in the database

We have been dealing with Hibernate objects that represents table records. In the inheritance posts we saw how to fetch records by referring to the base class. This would result in all sub class objects being fetched. In Java all classes extend the Object class.

Tuesday, 11 September 2012

Spring JDBC and SqlUpdate

In the previous posts we used the JDBC template's update() method to insert, update and delete data.There is another technique available if we do not want to work with the template.

Monday, 10 September 2012

Friday, 7 September 2012

Spring JDBC and SqlQuery

In an earlier post we saw how to use the JdbcTemplate to retrieve multiple rows from the database. There is an alternative way to do the same - using the org.springframework.jdbc.object.SqlQuery class.

Wednesday, 5 September 2012

Spring JDBC and the SqlFunction

In our previous post we saw how to use the JDBC templates to retrieve data. The template included wrappers to return scalar values from execution of SQL queries. For example consider the method from the previous example:

Tuesday, 4 September 2012

HQL and aliases

In the previous post we saw how query execution works in Hibernate and we created a simple relationship that we could use to test our different HQL queries.

Saturday, 1 September 2012

Querying with HQL - the basics

Hibernate provides us with its own query language - HQL or Hibernate Query Language. To understand the same I created a simple Entity class: