Announcement Announcement Module
Collapse
No announcement yet.
2.1-M2: resource type [javax.persistence.EntityManagerFactory] is not assignable to.. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 2.1-M2: resource type [javax.persistence.EntityManagerFactory] is not assignable to..

    When upgrading from 2.0 to 2.1 we are seeing this exception:

    (java.lang.String) Specified resource type [javax.persistence.EntityManagerFactory] is not assignable to field type

    In 2.0, spring would detect that an EMF was being injected into an EM and would obtain an EM from the EMF. Has this mechanism changed for 2.1?

    -barry

    ...

    Our LCEMFB is defined as:

    Code:
    <bean id="folio1.entityManagerFactory" lazy-init="true"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="Folio1" />
        <property name="dataSource" ref="folio1.dataSource" />
    </bean>
    
    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
    And is used via:

    Code:
    public class FooBar {
        @PersistenceUnit(unitName = "Folio1")
        private EntityManager folio1EntityManager;
        ...
    }
    The stack trace is:

    Code:
    ...
    Caused by: java.lang.IllegalStateException: Specified resource type [javax.persistence.EntityManagerFactory] is not assignable to field type [interface javax.persistence.EntityManager]
    	at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.checkResourceType(InjectionMetadata.java:98)
    	at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.<init>(PersistenceAnnotationBeanPostProcessor.java:488)
    	at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$1.doWith(PersistenceAnnotationBeanPostProcessor.java:313)
    	at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:276)
    	at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:253)
    	at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:308)
    	at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessAfterInstantiation(PersistenceAnnotationBeanPostProcessor.java:268)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:802)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:404)
    	... 26 more

  • #2
    answer - no spring problem!

    This one class was using @PersistenceUnit, when it should have been using @PersistenceContext. Apparently that the use of @PersistenceUnit worked in spring 2.0 for some reason.

    Comment

    Working...
    X