Thursday, April 16, 2009

Follow up to the AbstractHibernateDao

In my writing about the AbstractHibernateDao here I mention that you no longer need to extend HibernateDaoSupport class. You do lose one thing though. Your new AbstractHibernateDao based DAO will now throw HibernateExceptions, not Spring DataAccessExceptions. Now, to me, this isn't the end of the world. In a Hibernate 3.2+ world Hibernate does have a clear exception hierarchy. Not like the old days where there was just "HibernateException". That sucked.

If you do want your DAOs to throw Spring DataAccessExceptions there are two simple things to do.
  1. Add the @Repository annotation to your DAO impl.
  2. Add a PersistenceExceptionTranslationPostProcessor bean to your Spring setup.

What this does is tell Spring to wrap an interceptor around your DAO bean that handles the exception translation.

Looking at the UserDaoImpl from the past article...

@Repository
public class UserDaoImpl extends AbstractHibernateDao<User> implements UserDao {

public UserDaoImpl(SessionFactory sessionFactory) {
super(User.class, sessionFactory);
}
...
}

Then in your Spring application context.xml you simply add one line...




Now, this pattern I present is somewhat old school. There is all this fancy component scanning stuff you can do with the Spring 2.5 XML namespaces. Honestly the amount of voodoo that goes on there freaks me out a bit. You can study that on your own if you'd like. A good place to start is here.

Thursday, April 02, 2009

Amazon Elastic MapReduce

Amazon announced an Elastic MapReduce service in the AWS environment. This service combines S3, EC2 and the Hadoop MapReduce framework to provide a powerful distributed processing engine. This is pretty awesome stuff. Too bad I have no use for it right now, maybe I should make one up :P

Amazon Elastic MapReduce