Well, I've no patch to deliver but a workaround using <hbmtemplate>. It's going this way:
<hbm2dao> simply triggers an exporter (
http://anonhibernate.labs.jboss.com/tru ... orter.java). This exporter uses a template file you can find in the hibernate-tools.jar at dao/daohome.ftl.
I've simply copied this template and modified it a little bit to suit my needs: Receive Hibernate's SessionFactory through a constructor parameter - in a dependency injection-style fashion. I've named it my-dao-template.ftl.
Removing this part
---------------
private final ${pojo.importType("org.hibernate.SessionFactory")} sessionFactory = getSessionFactory();
protected ${pojo.importType("org.hibernate.SessionFactory")} getSessionFactory() {
try {
return (${pojo.importType("org.hibernate.SessionFactory")}) new ${pojo.importType("javax.naming.InitialContext")}().lookup("${sessionFactoryName}");
}
catch (Exception e) {
log.error("Could not locate SessionFactory in JNDI", e);
throw new IllegalStateException("Could not locate SessionFactory in JNDI");
}
---------------
and adding this one
---------------
private final ${pojo.importType("org.hibernate.SessionFactory")} sessionFactory;
/**
* Dependency injecting constructor.
*/
public ${declarationName}Home (final ${pojo.importType("org.hibernate.SessionFactory")} sessionFactory) {
super();
this.sessionFactory = sessionFactory;
}
---------------
should yield the required code.
Now add this code inside your ANT build.xml file's <hibernatetool>-Target:
<property key="ejb3" value="false"/>
<property key="jdk5" value="true"/>
<hbmtemplate
template="my-dao-template.ftl"
filepattern="{package-name}/{class-name}Home.java"/>
It is required to set some properties (namely ejb3 and jdk5) usually set by the DAOExporter class.
First make sure your template file "my-dao-template.ftl" is found in the classpath of hibernatetool. Second be aware of setting the filepattern correctly: It has to match the "Home"-suffixed class name used in the template.
This solution should open up your DAO to be configurable externally.
Greetings
Christian