Preferred code generation method
I want to use hbm2java to generate domain PoJos with both abstract and concrete classes. I also want to generate DTOs and DAOs. I’m using Spring so I want to include the spring templating in the generated DAOs (see example below).
I have been learning the capabilities of hbm2java and velocity. However, many of the posts recommend extending BasicRenderer over using the velocity templating? Is this still true and why?
I also prefer using hbm2java within ANT. The hbm files that the current eclipse tool generates does not include the aggregates (sets/lists). I’m using MySQL. What I want to do is specify the relationships using MiddleGen then pass the hbms to hbm2java and generate the custom pojo’s, TDOs, and DAOs.
The roadmap
http://www.hibernate.org/257.html includes comments about template based code generations. Is this via velocity?
What is the best path to custom code generation?
Middlegen -> hbm2java with custom velocity templates?
Code:
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.dygtig.domain.dao.hibernate;
import java.util.List;
import com.dygtig.domain.dao.*;
import com.dygtig.domain.businessobject.Actype;
import org.springframework.orm.hibernate3.support.*;
/**
* @author Baker
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class ActypeDaoHibernateImpl extends HibernateDaoSupport implements ActypeDao {
public Actype getActypeById(Long id) {
Actype actype = (Actype) this.getHibernateTemplate().load(Actype.class, id);
System.out.println(actype.getModel());
return actype;
}