Hi, I was happy using Hibernate 2.1.3 and I just migrated to hibernate 3 rc1 but this lead me into two problems while trying to use the well known SchemaExport Ant task :
- the task doesn't seem to be able to load the configuration from an xml file -> it outputs a "Dialect property not set" error (code below from the SchemaExport task explains why)
- I gave a try on the new nice annotation tool to replace my xdoclet generation but I did not found a way to parameterize the schemaExport task to use the mandatory AnnotationConfiguration required in that case.
May I missed something, but to solve those problems the only way out I see is to create my own Ant task so that the properties are correctly loaded, and the configuration used is an AnnotationConfiguration.
It is a not a big deal obviously, but for a release candidate I would have expected a package more finalized.
Regards.
Code from the hibernate 3rc1 SchemaExport tool:
Code:
//$Id: SchemaExportTask.java,v 1.3 2004/11/18 12:48:57 turin42 Exp $
private SchemaExport getSchemaExport(Configuration cfg) throws HibernateException, IOException {
SchemaExport schemaExport;
Properties properties = new Properties();
if (propertiesFile == null) { // null in the case of specified hibernate.cfg.xml file
properties.putAll(getProject().getProperties()); // load the ant project + jvm properties
}
else {
properties.load( new FileInputStream(propertiesFile) );
}
schemaExport = new SchemaExport(cfg, properties);
schemaExport.setOutputFile(outputFile);
schemaExport.setDelimiter(delimiter);
return schemaExport;
}
// In the new SchemaExport, the dialect is loaded from the "connectionProperties" parameter which in fact does not contains the expected properties
public SchemaExport(Configuration cfg, Properties connectionProperties) throws HibernateException {
this.connectionProperties = connectionProperties;
dialect = Dialect.getDialect(connectionProperties);
dropSQL = cfg.generateDropSchemaScript(dialect);
createSQL = cfg.generateSchemaCreationScript(dialect);
exceptions = new ArrayList();
}
// The right constructor to use is this one, I believe.
public SchemaExport(Configuration cfg) throws HibernateException {
this( cfg, cfg.getProperties() );
}
Ant output Code:
schema-export:
[schema-export] 09:35:14,864 INFO Environment:456 - Hibernate 3.0rc1
[schema-export] 09:35:14,873 INFO Environment:469 - hibernate.properties not found
[schema-export] 09:35:14,877 INFO Environment:502 - using CGLIB reflection optimizer
[schema-export] 09:35:14,882 INFO Environment:532 - using JDK 1.4 java.sql.Timestamp handling
[schema-export] 09:35:14,886 INFO Configuration:1262 - configuring from file: hibernate.cfg.xml
[schema-export] 09:35:15,475 INFO Configuration:439 - Mapping resource: fr/cns/laferme/core/common/robot/Robot.hbm.xml
[schema-export] 09:35:16,308 INFO HbmBinder:256 - Mapping class: fr.cns.laferme.core.common.robot.Robot -> ROBOT
[schema-export] 09:35:16,520 INFO Configuration:439 - Mapping resource: fr/cns/laferme/core/common/robot/Modele.hbm.xml
[schema-export] 09:35:17,365 INFO HbmBinder:256 - Mapping class: fr.cns.laferme.core.common.robot.Modele -> MODELE
[schema-export] 09:35:17,379 INFO Configuration:1340 - Configured SessionFactory: null
BUILD FAILED
workspace/LaFerme-core/build/build.xml:86: Following error occured while executing this line
workspace/LaFerme-core/build/build.xml:101: Schema text failed: The dialect was not set. Set the property hibernate.dialect.
Mapping file Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="hibernate.connection.url">jdbc:hsqldb:hsql://</property>
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.use_outer_join">true</property>
<property name="cglib.use_reflection_optimizer">true</property>
<property name="hibernate.connection.isolation">2</property>
<property name="hibernate.jdbc.batch_size">0</property>
<!-- Mapping files -->
<mapping resource="fr/cns/laferme/core/common/robot/Robot.hbm.xml"/>
<mapping resource="fr/cns/laferme/core/common/robot/Modele.hbm.xml"/>
<!-- Caching policies -->
</session-factory>
</hibernate-configuration>
Ant callCode:
<target name="schema-export">
<schema-export
config="${config.dir}/hibernate.cfg.xml"
quiet="no"
text="yes"
drop="no"
delimiter=";;"
output="${basedir}/build/dbscripts/schema-export.sql"/>
</target>