HibernateAnnotationComponentConfigurator

Ryan Sonnek bio photo By Ryan Sonnek

It’s been an impressively difficult task to improve upon the initial version of my Wicket/Hibernate integration, but I finally hit a break through. Introducing the new HibernateAnnotationComponentConfigurator. Long enough name for you?=)

This object is used to configure a Wicket Component based on Hibernate annotations. It inspects the Model of a FormComponent and configures the Component according to the declared Hibernate Annotations used on the Model object. This means the Component’s Model_must_be known when configuring a Component.

This object can be used as a Behavior to configure a single Component. NOTE: This object is stateless, and the same instance can be reused to configure multiple Components.

 public class MyWebPage extends WebPage {
   public MyWebPage() {
     TextField name = new TextField("id", new PropertyModel(user, "name");
     name.addBehavior(new HibernateAnnotationComponentConfigurator());
     add(name);
   }
 }

This object can also be used as a component listener that will automatically configure _all_FormComponents based on Hibernate annotations. This ensures that an entire application respects annotations without adding custom Validators or Behaviors to each FormComponent.

 public class MyApplication extends WebApplication {
   public void init() {
     addComponentOnBeforeRenderListener(new HibernateAnnotationComponentConfigurator());
   }
 }

I’m extremely excited that it is now possible for an entire application_to automatically use Hibernate annotations without any extra work. As far as I know, this is a first for _any Java web framework and just goes to show how much Wicket rocks.

So, what are you waiting for? Start using this today by downloading the latest build. Maven2 users have it even simpler by adding this to your POM.xml file:

<repositories>
  <repository>
    <id>wicket-stuff-repository</id>
    <name>Wicket-Stuff Repository</name>
    <url>http://www.wicketstuff.org/maven/repository/</url>
  </repository>
</repositories>

<dependencies>
  <dependency>
    <groupId>org.wicketstuff</groupId>
    <artifactId>wicketstuff-hibernate</artifactId>
    <version>1.3-SNAPSHOT</version>
  </dependency>
</dependencies>