-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Time to work on SchemaExport
PostPosted: Tue Mar 15, 2005 5:46 am 
Newbie

Joined: Tue Mar 15, 2005 5:06 am
Posts: 1
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 call
Code:
<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>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 17, 2005 1:01 am 
Beginner
Beginner

Joined: Mon Dec 15, 2003 5:25 am
Posts: 48
Location: Delhi, India
Use SchemaExport programmatically.

http://forum.hibernate.org/viewtopic.php?t=939492

_________________
Vinod K. Singh


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 17, 2005 6:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
and we will provide a more unified ant taskset in the next tools release.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 28, 2005 3:57 pm 
Newbie

Joined: Mon Oct 18, 2004 7:59 am
Posts: 10
Location: Netherlands
I found that configuring SchemaExport from hibernate.properties instead of hibernate.cfg.xml also helps.

But that shouldn't keep anyone from sanitizing SchemaExport.

mvg -
Marc


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.