简体   繁体   中英

how do i configure spring 2.5.6 + eclipseLink + weblogic 10.3

    <bean id="configProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="placeholderPrefix" value="${" />
    <property name="placeholderSuffix" value="}" />
    <property name="locations">
        <value>classpath:ddes/config.properties</value>
    </property>
</bean>

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="${datasource}"/>
    <property name="resourceRef" value="true"/>
</bean>

<context:load-time-weaver weaver-class="org.springframework.instrument.classloading.weblogic.WebLogicLoadTimeWeaver"/>

<bean id="PersistenceUnit" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
    <property name="defaultDataSource" ref="dataSource"/>
    <property name="class">
    <!--LIST BEANS-->
        <value>....</value>
    </property>
</bean>

<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
    <property name="databasePlatform" value="org.eclipse.persistence.platform.database.OraclePlatform"/>
    <property name="generateDdl" value="true"/>
    <property name="showSql" value="true"/>
</bean>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>
    <property name="persistenceUnitManager" ref="PersistenceUnit"/>
    <property name="persistenceUnitName" ref="Persistence-ejbPU"/>
    <property name="persistenceProvider" ref="org.eclipse.persistence.jpa.PersistenceProvider"/>
</bean>

<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="transactionManager" ref="entityManagerFactory"/>
</bean>

implement

@CallByReference
@Stateless(mappedName = "cliente") 
public class ClienteDAOBean implements ClienteDAOLocal, ClienteDAORemote {


    @PersistenceUnit(unitName = "Persistence-ejbPU")
    private EntityManagerFactory emf;

    public Clientes find(Integer codCliente) throws Exception {
        Clientes cliente = null;
        EntityManager em = emf.createEntityManager();
        try {
            javax.persistence.Query q = em.createNamedQuery("Clientes.findByCodCliente").setParameter("codCliente", codCliente);
            cliente = (Clientes) q.getSingleResult();
        } catch (Exception e) {
            throw e;
        } finally {
            em.close();
            return cliente;
        }
    }
}

Pero al iniciar la aplicación el log arroja este error:

No persistence unit named 'Persistence-ejbPU' is available in scope Persistence-ejbPU.jar

was previously using a persistence.xml file but needed the name of the datasource out dynamic

Simply replace ref with value. Use:

 <property name="persistenceUnitName" value="Persistence-ejbPU" />

instead of:

<property name="persistenceUnitName" ref="Persistence-ejbPU"/>

If you are having still problem then I would implement my own LocalContainerEntityManagerFactoryBean class which extends from AbstractEntityManagerFactoryBean so you can override setPersistenceUnitName then see what is going on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM