Using @Configurable on a domain object not working
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.
Code:
@Entity
@Inheritance(strategy = JOINED)
@Configurable
public abstract class Foo {
@Id
@GeneratedValue
private Long id;
private String aField;
}
A subclass with a dependency.
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;
}
}
I have an application context with component-scan and spring-configured.
Code:
<!-- Scan for annotated beans -->
<context:component-scan base-package="my.foo.bar"/>
<!-- Scan for non-managed classes with @Configurable -->
<context:spring-configured/>
The JPA implementation is Hibernate 4 and comes with JBoss AS 7 which we lookup through JNDI.
Code:
<!-- Lookup a container managed EMF -->
<jee:jndi-lookup id="entityManagerFactory"
jndi-name="java:jboss/entityManagerFactory"
expected-type="javax.persistence.EntityManagerFactory"/>
And I have Maven setup to compile with AspectJ. Java.version is 1.7.
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>
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.
Any ideas?