-
1. Re: EnversHibernateToolTask
drsaturno Sep 14, 2011 4:06 PM (in response to drsaturno)Ops, I forgot the xml ant file...
<target name="schemaexport" description="Gera ddls do amplis baseados nas parametrizações do hibernate">
<schemaExportTask configurationfiles="hibernate.cfg.xml,patrimonio.mapeamento.xml"
includes="**/*.hbm.xml"
outputfilename="${PATH}/${ddl-dir}/myproject-ddl.sql"
namingstrategy="br.com.ymf.myproject.base.hibernate.HibernateNamingDictionary"
drop="false"
create="true"
export="false"
delimiter=";" />
<DDLSplitterTask srcPath="${PATH}/${ddl-dir}/myproject-ddl.sql" />
</target>
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.EnversHibernateToolTask">
<classpath>
<fileset dir="${library-dir}">
<include name="**/*.jar" />
</fileset>
</classpath>
</taskdef>
<taskdef name="DDLSplitterTask" classname="br.com.ymf.myproject.tools.data.DDLSplitterTask">
<classpath id="tools" path="../MY_PROJECT/target/classes" />
<classpath>
<fileset dir="${library-dir}">
<include name="**/*.jar" />
</fileset>
</classpath>
</taskdef>
<taskdef name="schemaExportTask" classpathref="toolsClassPath"
classname="br.com.ymf.myproject.tools.build.hibernate.SchemaExportTask"/>
-
2. Re: EnversHibernateToolTask
adamw Sep 15, 2011 5:25 AM (in response to drsaturno)Could you debug and check if the AuditConfiguration.getFor get invoked? I'm not so fluent in the ant config so I can't spot any errors right now
Adam
-
3. Re: EnversHibernateToolTask
drsaturno Sep 16, 2011 5:03 PM (in response to adamw)Yep, I debugged and ConfigurationTaskWithEnvers is invoking AuditConfiguration.getFor(configuration).
BTW I'm using hibernate-envers-3.6.0.Final.jar
While debugging I realize that RevisionInfoConfigurationResult.configure can't find any classes in the 1st line:
Iterator<PersistentClass> classes = (Iterator<PersistentClass>) cfg.getClassMappings();
Maybe the problem is that I'm not using org.hibernate.tool.hbm2ddl.SchemaExport.
-
4. Re: EnversHibernateToolTask
drsaturno Sep 20, 2011 3:53 PM (in response to drsaturno)Trying to isolate the issue, I started to use the SchemeExport as recommended in Chapter 6: Generating schema with Ant
So I ignored my SchemaExport implementation and tried to use the hibernate tool's one:
<target name="schemaexport" description="Exports a generated schema to DB and file">
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.EnversHibernateToolTask"
classpathref="toolsClassPath"/>
<hibernatetool destdir=".">
<classpath>
<fileset dir="${library-dir}" >
<include name="**/*.hbm.xml" />
</fileset>
</classpath>
<configuration configurationfile="hibernate.cfg.xml"/>
<hbm2ddl
drop="false"
create="true"
export="false"
outputfilename="ddl.sql"
delimiter=";"
format="true"/>
</hibernatetool>
</target>
After some debuggin, the same problem, no audit tables created.
ConfigurationTaskWithEnvers is still invoking AuditConfiguration.getFor(configuration). Still the same empty classes on RevisionInfoConfigurationResult.configure, line Iterator<PersistentClass> classes = (Iterator<PersistentClass>) cfg.getClassMappings();
-
5. Re: EnversHibernateToolTask
drsaturno Sep 23, 2011 1:51 PM (in response to drsaturno)Well, I finally have some answers from my investigation.
Here is the catch:
final AnnotationConfigurationTaskWithEnvers configurationTask = (AnnotationConfigurationTaskWithEnvers) enversHibernateToolTask
.createAnnotationConfiguration();
yes,
createAnnotationConfiguration(), not createConfiguration()
and:
configurationTask.setConfigurationFile(new File("PROJECT_DIR\\src\\main\\resources\\hibernate.cfg.xml"));
and voilà.
But, if you, like me, have more than one hibernate.cfg.xml, you have a big problem. There´s no way to use more than one configuration file.
configurationTask.addConfiguredFileSet() doesn't work, because of this:
public class AnnotationConfigurationTaskWithEnvers extends AnnotationConfigurationTask {
protected void doConfiguration(Configuration configuration) {
/* Here we should have something like this:
for (int i = 0; i < configFiles.length; i++) {
configuration.configure(configFiles[i]);
}
configFiles represents all your hibernate.cfg.xml files
*/
super.doConfiguration(configuration);
configuration.buildMappings();
AuditConfiguration.getFor(configuration);
}
}
-
6. Re: EnversHibernateToolTask
adamw Sep 27, 2011 2:14 PM (in response to drsaturno)Hmm, I thought that the super.doConfiguration call will take care of things like that.
So you managed to get your code to work? What modifiactions exactly where needed?
I'd be happy to include any patches that would be necessary so that others don't have the same problem.Adam
-
7. Re: EnversHibernateToolTask
drsaturno Sep 27, 2011 4:21 PM (in response to adamw)Extracted from super.doConfiguration:
if (configurationFile != null) configuration.configure( configurationFile );
So, before invoking, we must have a configurationFile.
If we use addConfiguredFileSet(), this strategy doens't work, because we have to invoke configure() after involking addConfiguredFileSet(). But we can't do this, because we need to invoke getConfiguration() to get the configuration, and getConfiguration() do this:
if(cfg==null) {
cfg = createConfiguration();
doConfiguration(cfg);
cfg.buildMappings(); // needed otherwise not all assocations are made!
}
return cfg;
at this time, cfg is null, but we have no configuration files.
If we invoke configure() right after this, to use the configuration files, cfg is not null, so, doConfiguration is not called anymore.
-
8. Re: EnversHibernateToolTask
adamw Sep 29, 2011 7:19 AM (in response to drsaturno)But if call getConfiguration(), then add the files, then call AuditConfiguration.getFor(cfg), and then do the schema export, it works?
Generally this looks like a chicken-egg problem
Adam
-
9. Re: EnversHibernateToolTask
drsaturno Oct 5, 2011 5:29 PM (in response to adamw)Yep, a chicken-egg problem.
What would be the side effects of removing the if (verCfg == null) check of the AuditConfiguration.getFor(Configuration cfg)?
public synchronized static AuditConfiguration getFor(Configuration cfg) {
AuditConfiguration verCfg = cfgs.get(cfg);
if (verCfg == null) {
verCfg = new AuditConfiguration(cfg);
cfgs.put(cfg, verCfg);
cfg.buildMappings();
}
return verCfg;
}
-
10. Re: EnversHibernateToolTask
adamw Oct 10, 2011 11:57 AM (in response to drsaturno)Well this checks if a configuraiton was built already. Generally, it whould be called once for a complete Hibernate Configuration object.
Adam