Topic
  • 3 replies
  • Latest Post - ‏2011-01-13T14:25:07Z by sutter
SystemAdmin
SystemAdmin
45 Posts

Pinned topic Spring DB2 JPA Entity Manager Problem

‏2011-01-12T14:01:43Z |
Hi, I'm trying to configure Spring, JPA and DB2 in order to have the entity manager instance to be used in my spring controllers but according how I have configured Spring this not happens. These are the two attempts of configuration of spring:

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource" />
<bean name="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="em" />
</bean>
<bean id="em"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="fileUtility" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">
<property name="database" value="DB2" />
<property name="showSql" value="true" />
</bean>
</property>
</bean>

the second is this:

<!-- Entity manager factory bean. -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="Sample" />
</bean>

<!-- Entity manager bean. -->
<bean id="em" factory-bean="entityManagerFactory"
factory-method="createEntityManager" />

and the entity manager is injected in this way:

<bean id="messageService" class="utilities.services.impl.MessageServiceImpl">
<property name="entityManager" ref="em" />
</bean>

but I have always this exception:

Caused by: java.lang.IllegalArgumentException: methods with same signature createEntityManager() but incompatible return types: http://interface com.ibm.websphere.persistence.WsJpaEntityManager, interface org.apache.openjpa.persistence.OpenJPAEntityManagerSPI

I don't know how can be fixed. Has anyone encountered this problem?

Thanks in advance.

Also this is my persitence.xml configuration file:

<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
<persistence-unit name="fileUtility"
transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<mapping-file>META-INF/mapping.xml</mapping-file>
<properties>
<property name="openjpa.ConnectionURL" value="jdbc:db2://localhost:50000/db2admin" />
<property name="openjpa.ConnectionDriverName" value="COM.ibm.db2.jdbc.app.DB2Driver" />
<property name="openjpa.ConnectionUserName" value="db2admin" />
<property name="openjpa.ConnectionPassword" value="XXXX" />
<property name="openjpa.FlushBeforeQueries" value="true"/>
<property name="openjpa.RuntimeUnenhancedClasses" value="supported" />
</properties>

</persistence-unit>

<persistence-unit name="fileUtility2" transaction-type="JTA">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>file_ds</jta-data-source>
<mapping-file>META-INF/mapping.xml</mapping-file>
<properties>
<property name="openjpa.Log" value="SQL=TRACE"/>
<property name="openjpa.ConnectionFactoryProperties" value="PrettyPrint=true, PrettyPrintLineLength=72"/>
</properties>
</persistence-unit>
</persistence>
Updated on 2011-01-13T14:25:07Z at 2011-01-13T14:25:07Z by sutter
  • sutter
    sutter
    94 Posts

    Re: Spring DB2 JPA Entity Manager Problem

    ‏2011-01-12T15:15:50Z  
    Hi gcarlo,
    You don't mention the versions of the various software projects you are using... Via a quick Google search, I found this item on the Spring site [1], but this is from 2008... One of the responses on this thread stated this:

    Show Juergen Hoeller added a comment - 30/Jan/08 7:16 AM Unfortunately, the problem there is the EntityManagerFactory rather than the Entitymanager, so we'd have to introduce an "entityManagerFactoryInterface" property as well... I'll try to figure out a proper solution that will work for WebSphere as well. Juergen
    Permalink Juergen Hoeller added a comment - 30/Jan/08 8:18 AM

    I've introduced a corresponding "entityManagerFactoryInterface" property, auto-populated from the JpaVendorAdapter by default. So as of the next snapshot (388), this should work out of the box, just through specifying OpenJpaVendorAdapter. Juergen

    From this exchange, it sounds like Spring resolved this issue "out of the box". So, can you verify that you are running with the proper levels of Spring?

    BTW, we have also changed this WAS and OpenJPA EM and EMF heirarchy in our latest WAS releases, so we should be in good shape all the way around.

    Hope this helps,
    Kevin

    [1] https://jira.springframework.org/browse/SPR-4383
  • SystemAdmin
    SystemAdmin
    45 Posts

    Re: Spring DB2 JPA Entity Manager Problem

    ‏2011-01-12T17:31:10Z  
    • sutter
    • ‏2011-01-12T15:15:50Z
    Hi gcarlo,
    You don't mention the versions of the various software projects you are using... Via a quick Google search, I found this item on the Spring site [1], but this is from 2008... One of the responses on this thread stated this:

    Show Juergen Hoeller added a comment - 30/Jan/08 7:16 AM Unfortunately, the problem there is the EntityManagerFactory rather than the Entitymanager, so we'd have to introduce an "entityManagerFactoryInterface" property as well... I'll try to figure out a proper solution that will work for WebSphere as well. Juergen
    Permalink Juergen Hoeller added a comment - 30/Jan/08 8:18 AM

    I've introduced a corresponding "entityManagerFactoryInterface" property, auto-populated from the JpaVendorAdapter by default. So as of the next snapshot (388), this should work out of the box, just through specifying OpenJpaVendorAdapter. Juergen

    From this exchange, it sounds like Spring resolved this issue "out of the box". So, can you verify that you are running with the proper levels of Spring?

    BTW, we have also changed this WAS and OpenJPA EM and EMF heirarchy in our latest WAS releases, so we should be in good shape all the way around.

    Hope this helps,
    Kevin

    [1] https://jira.springframework.org/browse/SPR-4383
    I have this exception with both spring 2 and 3, I had read the item in the Spring site, but now I have a questions to you: what are the proper levels of Spring that I should verify? You mean the version?
  • sutter
    sutter
    94 Posts

    Re: Spring DB2 JPA Entity Manager Problem

    ‏2011-01-13T14:25:07Z  
    I have this exception with both spring 2 and 3, I had read the item in the Spring site, but now I have a questions to you: what are the proper levels of Spring that I should verify? You mean the version?
    Hi gcarlo,
    Supposedly, the problem I referenced was resolved in Spring 2.5.2. If you are running with Spring 3.x, I would have assumed this would have been resolved in that version.

    Have you checked out this helpful article [1]? Tom and friends have provided several helpful hints and best practices with integrating Spring with WebSphere and JPA. I also just noticed that this article referenced the same bug report in Spring [2] that I did.

    I would review that article to see if your environment is following the suggestions outlined. I would also double check to ensure that the version of Spring that you are using has the fixes for 4383 in it (this is a question for Spring). If your scenario is still failing, please post more information on your environment (versions of Spring and WebSphere) to this forum. And, I would also post your question to the Spring forums. At this point, the data is pointing at a Spring issue, but I can't be sure.

    Good luck,
    Kevin

    [1] http://www.ibm.com/developerworks/websphere/techjournal/0609_alcott/0609_alcott.html
    [2] https://jira.springframework.org/browse/SPR-4383