Announcement Announcement Module
Collapse
No announcement yet.
Compile time weaving and domain objects loaded by hibernate. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Compile time weaving and domain objects loaded by hibernate.

    Hello folks,

    I'm getting the following error when I run my integration tests:

    Code:
    java.lang.IllegalStateException: Property 'transactionManager' must be set on transaction aspect
    I'm using maven and I set up the plugin for compile time weaving of my domain classes (rich domain model):

    Code:
    <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>aspectj-maven-plugin</artifactId>
                    <configuration>
                        <complianceLevel>1.6</complianceLevel>
                        <aspectLibraries>
                            <aspectLibrary>
                                <groupId>org.springframework</groupId>
                                <artifactId>spring-aspects</artifactId>
                            </aspectLibrary>
                        </aspectLibraries>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>compile</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
    My domain class is annotated with @Configurable and it has a @Resource on one of its dependencies. This configuration is properly done because if I create a Spring application context and create my domain object with the "new" operator, the dependencies are injected as expected.

    However, I also created a service class which loads this domain object by using an hibernate dao. This hibernate dao and service are wired together by standard xml configuration. I have annotated the service and dao intefaces with @Transactional.

    My integration test creates a new instance of the domain object (by using new) and then asks the service (obtained from spring application context) to persist it. The service in turns delegates to the dao. After the object is persisted, I use the same service to load the persisted object by its id and compare the properties to make sure everything was persisted correctly.

    I get the error above when I try to persist the domain object. If i disable compile time weaving, then the test works as expected and the object is correctly persisted, but the domain object stops being injected with its dependencies.

    I noticed that hibernate is always returning a javassist proxy of the domain object, even if there are no collections mapped in it.

    Any ideas on what the problem might be? Is aspectj weaving incompatible with hibernate entities?

    ***************************************
    Edited: I solved the first issue: I was creating the service using new instead of getting it from the application context.

    Now I am facing another issue. Hibernate is returning a proxy of my domain object (DomainObject_$$_javassist_0). This is making the objects pretty much useless as even a simple getName() method call will attempt to access the database (and by the time I need to call it the session will not be available anymore). Spring is still not able to inject the dependencies on this proxy.



    ***************************************
    Edited 2: Problem solved. I was using Session.load(). Now I'm using Session.get(). Everything is working as expected now.
    Last edited by daniel.mfreitas; Jul 27th, 2009, 05:43 PM.
Working...
X