Category Archives: hibernate

Tapestry Grid & Hibernate Criteria

Tapestry Grid is a very powerful tool for displaying a list of entities. It expects a GridDataSource as source parameter. A useful tool can be a TypeCoercer which converts a Criteria to GridDataSource. Continue reading

Tapestry hibernate multiple databases

In a recent project, I had a requirement of connecting to multiple databases using hibernate. As tapestry-hibernate module does not provide an out-of-box support, I thought of adding one.

Now that the application is in production, I thought of writing a simple “How to”.
Continue reading

Tapestry Magic #13: Generic Data Access Objects

With the help of modern day ORMs, Generic DAOs are very easy to create. All we need from an IOC is the ability to differentiate between two services(implementing the same interface) by their generic type.The problem is tapestry-ioc can differentiate between two services based on service Id or marker annotations, not by generic type. So, if we have a generic DAO implementation, we cannot do something like

private EntityDAO<User> userDAO;

(Note, I am using the term EntityDAO for a generic dao.) One of the solutions will be something like

private EntityDAO<User> userDAO;

Another one can be

private EntityDAO<User> userDAO;

The latter one can be implemented if we are able to expose our DAO as a service. The former one can be then implemented in terms of the latter one using class transformations.

The second issue is how to register a DAO for each entity. It can be done manually like

static public EntityDAO<User> buildUserDAO(){
   return new EntityDAOImpl(User.class);

But imagine doing this for a database with hundreds of entities(especially if you are a lazy tapestry user). A solution will be to load the entities at start-up and create corresponding DAOs. This would have been great but tapestry does not provide a dynamic way of contributing new services. Yes, you can contribute an ObjectProvider to the MasterObjectProvider, but with that you are creating an object, not a service. Some of the features that you loose with that is the ability to directly apply advices to your services and not able to use @InjectService annotation.
Continue reading

Tapestry Magic #12 : Tapestry IOC aware JSR-303 Custom Validators

In JSR-303, adding a custom field validator is a two step process.

  1. Create an annotation which will be placed on a field to be validated
  2. Create a validator which implements ConstraintValidator and link it to the above annotation

Continue reading

Tapestry Magic #9: Integrating with hibernate and multiple database support

Tapestry5 already has a module for integration with hibernate. This module is restricted to only one database. In this post I will create a small module which can support multiple databases. I am not going to provide all the facilities that tapestry-hibernate module already provides but just enough to solve the multiple database access problem. Continue reading

%d bloggers like this: