views:

22

answers:

1

Hi *,

I'm looking for a callback facility that allows me to execute some code before an EntityManager is started in JBoss 6.

More specifically, I would like to process a Liquibase changelog, before the EntityManager is initialized.

Any hints greatly appreciated! J.

A: 

Are you using Spring or AspectJ? It sounds like writing an aspect is exactly what you want:

7.2.4.1 Before advice

Before advice is declared in an aspect using the @Before annotation:

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

@Aspect
public class LiquibaseChangelogAspect {

  @Before("javax.persistence.EntityManagerFactory.createEntityManager()")
  public void processChangelog() {
    // ...
  }

}

You might have to tweak the method name in the @Before annotation to exactly what you want because JBoss might be using proxies or whatever.

The Alchemist
Interesting approach... However, I'm not using Spring, nor AspectJ. Maybe JEE6 Interceptors can deliver the same functionality?
Jan
Yeah, looking at `javax.interceptor`, looks like interceptors would work too! Good call.
The Alchemist