I'm trying to use @Configurable with AspectJ at compile time in Maven to inject dependencies into JPA entities created by Hibernate in a JBoss environment. Dependency injection on these works perfectly with the new operator but anything created by Hibernate does not get injected.
I have a parent entity.
A subclass with a dependency.Code:@Entity @Inheritance(strategy = JOINED) @Configurable public abstract class Foo { @Id @GeneratedValue private Long id; private String aField; }
I have an application context with component-scan and spring-configured.Code:@Entity @Configurable public class Bar extends Foo { private String anotherField; @Transient private TaskScheduler dependency; @Autowired public void setDependency(final TaskScheduler dependency) { this.dependency = dependency; } }
The JPA implementation is Hibernate 4 and comes with JBoss AS 7 which we lookup through JNDI.Code:<!-- Scan for annotated beans --> <context:component-scan base-package="my.foo.bar"/> <!-- Scan for non-managed classes with @Configurable --> <context:spring-configured/>
And I have Maven setup to compile with AspectJ. Java.version is 1.7.Code:<!-- Lookup a container managed EMF --> <jee:jndi-lookup id="entityManagerFactory" jndi-name="java:jboss/entityManagerFactory" expected-type="javax.persistence.EntityManagerFactory"/>
Again, this works perfectly with the new operator, but does not work at all with entities created by Hibernate. So the dependency is there and can be configured, Spring is picking up the @Configurable and working fine, there must be something different with how Hibernate instantiates that isn't getting picked up.Code:<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <version>1.4</version> <configuration> <complianceLevel>${java.version}</complianceLevel> <source>${java.version}</source> <target>${java.version}</target> <aspectLibraries> <aspectLibrary> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> </aspectLibrary> </aspectLibraries> </configuration> <executions> <execution> <goals> <goal>compile</goal> <goal>test-compile</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.7.1</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjtools</artifactId> <version>1.7.1</version> </dependency> </dependencies> </plugin>
Any ideas?


Reply With Quote