Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Generics and Eclipselink
Generics and Eclipselink [message #389737] Thu, 25 June 2009 12:19 Go to next message
Enrico is currently offline EnricoFriend
Messages: 82
Registered: July 2009
Member
Hi all. I am new in EclipseLink, so I hope my question wiil be not too
dummy :-)
I would like to know if there is an easy way to use generics and
eclipselink jpa in order to implement DAO for generics object. I know for
example that using Hibernate there is an HibernateDaoSupport that allow to
handle this. Is this possible using also eclipselink?
To be more clear, i would like to have something similar to
http://blog.grumblesmurf.org/2007/10/generics-makes-daos-eas y.html
but using eclipselink ORM.

Best Regards,
Enrico
Re: Generics and Eclipselink [message #389745 is a reply to message #389737] Thu, 25 June 2009 14:19 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Should be pretty simple to do this.

Something like:
public abstract class BaseDAOJPA<T>
implements BaseDAO<T> {
public void save(T object) {
getEntityManager().merge(object);
}

public T get(Serializable id) {
return getEntityManager().find(getModelClass(), id);
}

public void remove(T object) {
getEntityManager().remove(object);
}

public void remove(Serializable id) {
remove(get(id));
}

@SuppressWarnings("unchecked")
public List<T> loadAll() {
return getEntityManager().createQuery("Select o from " +
getModelClass().getSimpleName() + " o");
}

protected abstract Class<T> getModelClass();
}


---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Previous Topic:remove not removing
Next Topic:Order of persit operations not preserved?
Goto Forum:
  


Current Time: Fri Mar 29 13:56:24 GMT 2024

Powered by FUDForum. Page generated in 0.02986 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top