views:

121

answers:

1

I have just started studying Spring framework. My current goal is to access database from my bean through JPA (TopLink** provider) on Geronimo server. But I can't overcome the problem of getting entityManagerFactory.

The exception I get:

java.lang.IllegalStateException: ClassLoader [org.apache.geronimo.kernel.config.MultiParentClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:spring-agent.jar

The way I access it:

    <context:load-time-weaver />

    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceXmlLocation" value="classpath:/META-INF/persistence.xml" />
    </bean>

    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    <bean name="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
    <tx:annotation-driven />

I will be very grateful if anyone can help me without using "-javaagent:spring-agent.jar" option.


Searching a solution. First attempt.

Following "axtavt" advice, I found example of specifying special class loader for your web application on Tomcat. It uses context.xml file for that purpose. Although my Geronimo uses Tomcat, I didn't succeed implementing context.xml. As is said in the next manual the alternative for context.xml for Geronimo is geronimo-tomcat.xml, but it's syntax doesn't provide any possibilities for changing classloader. I still need help!


+1  A: 

Toplink requires a load-time weaving support. I guess in Geronimo it can be configured by using META-INF/context.xml and putting instrumentation jar into lib folder, as in Tomcat, see here.

EDIT: So, your problem is that Toplink requires class transformation support. When Toplink's entity manager is configured in Spring's configuration (LocalContainerEntityManagerFactoryBean), it tries to use Spring's support for class transformation (<context:load-time-weaver />), but Spring doesn't have a built-in support for class transformation in Geronimo. So, you have 3 options:

  1. Use JPA implementation which doesn't require class transformation instead of Toplink (for example, Hibernate)
  2. Don't configure Toplink's entity manager in Spring configuration file. Configure it using Geronimo configuration (I don't know how) and obtain it using JNDI.
  3. For maniacs: Implement a custom LoadTimeWeaver for Geronimo (I guess, it will use TransformerAgent.addTransformer()).
axtavt
Hi, it seems to be the right way, but i failed to find any alternative for context.xml. I updated my question.
Denis
@Denis: Answer edited.
axtavt
Hello! I have a question due to using Hibernate. Where can I find "org.hibernate.ejb.HibernatePersistence" class? I have decided to use maven and place following artifact as dependency "org.hibernate:hibernate-entitymanager". Maven added three hibernate related jars to my project. Two of them are connected with using annotations and the third is core, but none of them contain required class "org.hibernate.ejb.HibernatePersistence". The instructions I followed: http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html/configuration.html
Denis