Need a code generation tool for DAO companies.

I have many objects in the project, and I need to make a data access object for each of them. I think that these DAOs will be a stateless beans session, each of which will have an entity manager (I'm not sure about that, but since I will use them in the context of JBoss AS, does this look reasonable. Advice?).
Is there any tool (ideally, the maven plugin) that can scan my object classes, process their annotations and generate those beans for me? Each bean must expose methods for creating or deleting objects, as well as for each of the named queries of the corresponding entity class, as a separate method. To be more precise, I want something like this article:
http://community.jboss.org/people/ilya40umov/blog/2011/01/06/genericejb-based-jpa-entitymanager-extension
but with different methods for each named request. I will use JPA 2.0 with Hibernate 4.0. Thanks in advance! Edit: Stupid me, I forgot to mention that I don't use spring, and the term DAO is just used to illustrate what I want ...

+4
source share
3 answers

Telosys Tools is designed for this kind of task. It generates code from a database model.

See https://sites.google.com/site/telosystools/

You can use part of this lesson https://sites.google.com/site/telosystutorial/springmvc-jpa-springdatajpa to create only a part of JPA

You can also create your own templates to suit your needs (or adapt existing templates)

+4
source

you could use generics and meditations to do something like this

public interface IDao<T> { public <A extends Serializable> T getElementByID(A x); public Long getRowsCount(); public List<T> getAll(); public List<T> getAll(String order); public void saveOrUpdateElement(T x); public void updateElement(T x); public void saveElement(T x); public void deleteElement(T x); public void setClase(Class<T> clase); public Class<T> getClase(); public void mergeElement(T x); public T getFirst(); 

}

method public void setClase (class clase); do all the magic, so if you need to request x, then you will set the class, and the implementation, for example, getAll () will be

 public List<T> getAll(){ return session.createQuery("from "+getClase().getSimpleName()).list(); 

}

+1
source

Take a look at Spring-Data-JPA or Spring ROO

0
source

All Articles