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 {
	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");
			isExternal = true;
		return uow;
	public Object clone(Object entity){
		return getUnitOfWork().registerObject(entity);		
	public void commit(){
	public List readAll(Class clazz, Expression expression ){
		return (List)getUnitOfWork().readAllObjects(clazz,expression);
	public List readAll(Class clazz){
		return (List)getUnitOfWork().readAllObjects(clazz);
	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="";
	<persistence-unit name="dyltPersistenceUnit">
        <property name="" 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"/>        

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
View this message in context:
Sent from the EclipseLink - Users mailing list archive at

Back to the top