Thanks for the suggestions, guys. I like the hibernate.cfg.xml way best; I think I'll switch to using this method, as it is much easier to maintain.
--Steven On 5/20/05, Achmad Arif Rachim <[EMAIL PROTECTED]> wrote: > Hi stefen, > > Im using <hibernatedoclet/> to create hibernate.cfg.xml, the *.hbm.xml > automagicly registered inside it. So u can use session factory with > hibernate.cfg.xml instead. No pain and quite neat ;) > > > On 5/20/05, Steven Wisener <[EMAIL PROTECTED]> wrote: > > > > I'm using XDoclet to generate both my Hibernate and Spring XML files. > > Since the spring.xml file needs to contain a list of the Hibernate XML > > files, I decided to write a little glue code to piece it all together. > > I wanted to share my approach in case anyone else needed to do the > > same thing. First I wrote an xdt file that generates the list of > > hibernate XML files to include in the spring.xml, which I called > > hibernate_spring_xml.xdt: > > > > <list> > > <XDtClass:forAllClasses> > > <XDtClass:ifHasClassTag tagName="hibernate.class"> > > > <value><XDtPackage:packageNameAsPath/>/<XDtClass:className/>.hbm.xml</value> > > </XDtClass:ifHasClassTag> > > </XDtClass:forAllClasses> > > </list> > > > > This template needs to get run when hibernatedoclet runs. I'm using > > Maven, so I included a template task when running it. Here is the > > relevant portion of the project.properties file: > > > > # Hibernate > > > maven.xdoclet.hibernatedoclet.destDir=${maven.build.dir}/xdoclet/hibernatedoclet > > maven.xdoclet.hibernatedoclet.fileset.0=true > > maven.xdoclet.hibernatedoclet.fileset.0.include=**/*.java > > maven.xdoclet.hibernatedoclet.hibernate.0=true > > maven.xdoclet.hibernatedoclet.hibernate.0.Version=3.0 > > > > # Hibernate/Spring glue > > maven.xdoclet.hibernatedoclet.template.0=true > > > maven.xdoclet.hibernatedoclet.template.0.templateFile=template/hibernate_spring_xml.xdt > > > maven.xdoclet.hibernatedoclet.template.0.destinationFile=hibernate_spring.xml > > > > # Spring > > > maven.xdoclet.springdoclet.destDir=${maven.build.dir}/xdoclet/springdoclet > > maven.xdoclet.springdoclet.fileset.0=true > > maven.xdoclet.springdoclet.fileset.0.include=**/*.java > > maven.xdoclet.springdoclet.springxml.0=true > > > maven.xdoclet.springdoclet.springxml.0.mergeDir=${maven.build.dir}/merge > > > > In the Hibernate/Spring glue section, you can see that the template > > task will generate a file called hibernate_spring.xml. From there, we > > need to get that section of code into spring-beans.xml so that it can > > get merged into spring.xml. I have a file called spring-beans.xml.base > > that contains a @HIBERNATE_MAPPINGS@ token to be replaced by the > > contents of the generated hibernate_spring.xml file: > > > > ...some beans... > > > > <bean > > id="sessionFactory" > > > class="org.springframework.orm.hibernate.LocalSessionFactoryBean > "> > > <property name="dataSource"><ref local="dataSource"/></property> > > <property name="mappingResources"> > > @HIBERNATE_MAPPINGS@ > > </property> > > <property name="hibernateProperties"> > > <props> > > <prop key="hibernate.dialect">mydialect</prop> > > </props> > > </property> > > </bean> > > > > In maven.xml, I replace the @HIBERNATE_MAPPINGS@ token, with the > > loadfile/copy tasks. Then I just merge in the resulting spring-beans.xml > > file: > > > > <!-- Generate Hibernate and Spring XML files --> > > <preGoal name="java:compile"> > > <mkdir dir="${maven.xdoclet.hibernatedoclet.destDir}"/> > > <attainGoal name="xdoclet:hibernatedoclet" /> > > > > <!-- Copy hibernate mapping references into spring-beans.xml --> > > <mkdir dir="${maven.build.dir}/merge"/> > > > > <loadfile > srcFile="${maven.build.dir}/xdoclet/hibernatedoclet/hibernate_spring.xml" > > property="hibernate.mappings"/> > > > > <copy file="${basedir}/src/merge/spring-beans.xml.base" > > tofile="${maven.build.dir}/merge/spring-beans.xml"> > > <filterset> > > <filter token="HIBERNATE_MAPPINGS" value="${ hibernate.mappings}"/> > > </filterset> > > </copy> > > > > <mkdir dir="${maven.xdoclet.springdoclet.destDir}"/> > > <attainGoal name="xdoclet:springdoclet" /> > > </preGoal> > > > > This solution has a lot of moving parts, but it seems to work. > > Although I used Maven to do this, it should be pretty easy to > > replicate in Ant. If anyone has any improvements/alternatives to this > > method, please let me know. > > > > --Steven > > > > > > ------------------------------------------------------- > > This SF.Net email is sponsored by Oracle Space Sweepstakes > > Want to be the first software developer in space? > > Enter now for the Oracle Space Sweepstakes! > > http://ads.osdn.com/?ad_idt12&alloc_id344&opclick > > _______________________________________________ > > xdoclet-user mailing list > > xdoclet-user@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/xdoclet-user > > > > ------------------------------------------------------- This SF.Net email is sponsored by Yahoo. Introducing Yahoo! Search Developer Network - Create apps using Yahoo! Search APIs Find out how you can build Yahoo! directly into your own Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005 _______________________________________________ xdoclet-user mailing list xdoclet-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xdoclet-user