Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] How to use EclipseLink Native API with JPA

I have a native JPA application and want to incorporate some features of
Eclipselink, such as query by example, unit-of-work and expressions. I've
created a utility facade to encapsulate these features as follows:

public class BaseDAO {
	
	@PersistenceContext
	private EntityManager em;
	
	private boolean isExternal = false;	
		
	public boolean isExternal() {
		return isExternal;
	}

	public Session getSession(){
		JpaEntityManager emImpl = (JpaEntityManager)em.getDelegate();
		return emImpl.getSession();
	}
		
	public UnitOfWork getUnitOfWork(){
		UnitOfWork uow = getSession().getActiveUnitOfWork();
		if(uow == null){
			uow = getSession().acquireUnitOfWork();
			if(uow == null)
				throw new RuntimeException("No transaction started");
			
		}else
			isExternal = true;
		
		return uow;
	}
	
	public Object clone(Object entity){
		return getUnitOfWork().registerObject(entity);		
	}
		
	public void commit(){
		getUnitOfWork().commit();
	}
	
	@SuppressWarnings("unchecked")
	public List readAll(Class clazz, Expression expression ){
		return (List)getUnitOfWork().readAllObjects(clazz,expression);
	}
	
	@SuppressWarnings("unchecked")
	public List readAll(Class clazz){
		return (List)getUnitOfWork().readAllObjects(clazz);
	}
	
	@SuppressWarnings("unchecked")
	public List readAll(Class clazz, Call call){
		return (List)getUnitOfWork().readAllObjects(clazz, call);
	}
		
}

My persistence.xml is pretty basic:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" 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";>
	<persistence-unit name="dyltPersistenceUnit">
	   <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
	   <jta-data-source>java:/DyltDS</jta-data-source>
	   <mapping-file>META-INF/orm-messages.xml</mapping-file>
	   <mapping-file>META-INF/orm-allcode.xml</mapping-file>
	   <mapping-file>META-INF/orm-zip.xml</mapping-file>
	   <properties>
        <property name="eclipselink.target-server" value="JBoss"/>
        <property name="eclipselink.logging.level" value="FINEST"/>
        <property name="eclipselink.cache.size.default" value="500"/>
        <property name="eclipselink.cache.type.default" value="Full"/>        
       </properties>
	</persistence-unit>	
</persistence>


Does anyone have experience combining the two? Do I have to specifically
configure Eclipselink caching to use unit-of-work and some of the other
features. And what about weaving? Is it required to use, say,  lazy-loading
or any other specific Eclipselink capabilities. I mean, I thought native JPA
can handle lazy loading out-of-the box. The documentation on using JPA and
Eclipslink is under construction, so any help out there would be
appreciated. 
-- 
View this message in context: http://www.nabble.com/How-to-use-EclipseLink-Native-API-with-JPA-tp19761716p19761716.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top