Announcement Announcement Module
No announcement yet.
Using @Configurable on a domain object not working Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

    @Inheritance(strategy = JOINED)
    public abstract class Foo {
        private Long id;
        private String aField;
    A subclass with a dependency.

    public class Bar extends Foo {
       private String anotherField;
       private TaskScheduler dependency;
       public void setDependency(final TaskScheduler dependency) {
            this.dependency = dependency;
    I have an application context with component-scan and spring-configured.

        <!-- Scan for annotated beans -->
        <context:component-scan base-package=""/>
        <!-- Scan for non-managed classes with @Configurable -->
    The JPA implementation is Hibernate 4 and comes with JBoss AS 7 which we lookup through JNDI.

        <!-- Lookup a container managed EMF -->
        <jee:jndi-lookup id="entityManagerFactory"
    And I have Maven setup to compile with AspectJ. Java.version is 1.7.

    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?

  • #2
    I've discovered the issue. The particular entities in question were being loaded as part of a 'startup' job that was not waiting for the application context to finish initializing. Thus they were being created before the AnnotationBeanConfigurerAspect had been initialized and configured. Forcing the entire process to wait until after the context has finished loading fixes the issue.


    • #3
      I am using Spring data audit, but encountered the same problem, the auditingEntityListenser does not work as expected.

      How to overcome this issue?