You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Rossmy Tilman <Ti...@rtc.ch> on 2009/05/11 13:11:28 UTC

jpa with orchestra and spring

I'm using the orchestra lib in my project and with the conversation scope nopw everything seems to be fine. But the request scope does not work anymore. That is due to the fact that
the spring (as opposed to orchestra) managed persistence business object expects a @Transitional annotation above its constructor, while orchestra does not allow this at all...so what's the suggested strategy here, have different business objects for different scopes?
( Right now I'm using one business object for all my managed beans like this:
public interface BaseBO
{
    public <T> List<T> query(String queryString, final Object... params);

    public int updateQuery(String queryString, final Object... params);

    public int nativeUpdateQuery(String queryString, Object... params);

    public <T> List<T> queryPaginated(String queryString, int firstResult, int maxResult, final Object... params);

    public <T> T merge(T entity);

    public void persist(Object... entities);

    public <T> T find(Class<T> clazz, Object id);

    public List<Object> findByNamedQueryAndNamedParams(String string, Map<String, Object> map);

    public <T> List<T> findAll(Class<T> clazz);

    public void remove(Object object);

    public <T> List<T> findAll(Class<T> name, int i);
}

this is the entityManger configuration:

<tx:annotation-driven transaction-manager="transactionManager"/>
    <!--suppress DuplicatedBeanNamesInspection -->
    <jee:jndi-lookup id="dataSource" jndi-name="jdbc/cyberadmin"/>
    <!--suppress DuplicatedBeanNamesInspection -->
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="cyberIbis"/>
        <property name="dataSource" ref="dataSource"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="false"/>
                <property name="databasePlatform" value="org.hibernate.dialect.Oracle9iDialect"/>
                <property name="generateDdl" value="false"/>
            </bean>
        </property>
        <property name="jpaDialect">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
        </property>
    </bean>
    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor">
        <property name="defaultPersistenceUnitName" value="cyberIbis"/>
    </bean>
    <!--suppress DuplicatedBeanNamesInspection -->
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>

and this the orchestra conf:

<!-- 1. initialization of all orchestra modules (required for core15 module) -->
    <import resource="classpath*:/META-INF/spring-orchestra-init.xml"/>

    <!-- 2. the conversation scopes -->
    <bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
        <property name="scopes">
            <map>
                <entry key="conversation.manual">
                    <bean class="org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope">
                        <property name="advices">
                            <list>
                                <ref bean="persistentContextConversationInterceptor"/>
                            </list>
                        </property>
                        <property name="timeout" value="60"/>
                    </bean>
                </entry>
                <entry key="conversation.access">
                    <bean class="org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope">
                        <property name="advices">
                            <list>
                                <ref bean="persistentContextConversationInterceptor"/>
                            </list>
                        </property>
                        <property name="lifetime" value="access"/>
                        <property name="timeout" value="30"/>
                    </bean>
                </entry>
            </map>

        </property>
    </bean>

    <!-- 3. the "entity manager" manager -->
    <bean id="persistentContextConversationInterceptor"
          class="org.apache.myfaces.orchestra.conversation.spring.PersistenceContextConversationInterceptor">
        <aop:scoped-proxy/>
        <property name="persistenceContextFactory" ref="persistentContextFactory"/>
    </bean>

    <!-- 4. conversation - persistence adapter -->
    <bean id="persistentContextFactory"
          class="org.apache.myfaces.orchestra.conversation.spring.JpaPersistenceContextFactory">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>