Hi,

in my DAO i am injecting via Spring:

    @PersistenceContext
    private EntityManager em;

    public void save(WSO wso) {
        OpenJPAEntityManager oem = (OpenJPAEntityManager) em;
        if (oem.isDetached(wso)) {
            em.merge(wso);
        } else {
            em.persist(wso);
        }
    }

But the "em" is not compatible with OpenJPAEntityManager, so i get a ClassCastException. My boostrapping code via Spring looks like this:

 <bean id="entityManagerFactory"
class ="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="myDataSource"/>
        <!--
        <property name="loadTimeWeaver">
<bean class = "org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver"/>
        </property>
        -->
    </bean>

And my persistence.xml:

<persistence xmlns="http://java.sun.com/xml/ns/persistence";
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://java.sun.com/xml/ns/ persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd";
             version="1.0">
    <persistence-unit name="punit">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</ provider>
        <properties>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/> <property name="openjpa.DetachState" value="fetch- groups(DetachedStateField=true)"/>
        </properties>
    </persistence-unit>
</persistence>

So how can i use methods only available in OpenJPAEntityManager? Its somehow ugly anyway to ask if its detached and then do a merge or persist. I couldnt remember that this was the case with Kodo.

Thx for ideas.

Marc

Reply via email to