-->
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.  [ 10 posts ] 
Author Message
 Post subject: schema export ant task
PostPosted: Sun Nov 16, 2008 9:19 pm 
Newbie

Joined: Sun Nov 16, 2008 8:28 pm
Posts: 14
Location: Hamburg
Hi all,

I spent many hours in the last week to a problem with a hibernate 3 SchemaExportTask called by ant, but I don't find a solution. I hope that anybody can help me.

Always if I run the task I will become the same error message:

Schema text failed: resource: com/project/service/hibernate/Country.hbm.xml not found

Code:
Buildfile: I:\project\dev\workspace\projectBackend\build.xml
_create db-schema:
     [echo] The database schema will be created related by the hibernate mapping...
[schemaexport] log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
[schemaexport] log4j:WARN Please initialize the log4j system properly.

BUILD FAILED
I:\project\dev\workspace\projectBackend\build.xml:135: Schema text failed: resource: com/project/service/hibernate/Country.hbm.xml not found

Total time: 953 milliseconds


So my opinion is that there is an erroneous classpath, but it looks clean (build.xml):

Code:
...
<property name="classes.dir" value="classes"/>
<property name="lib.dir" value="lib"/>
...
<path id="lib.class.path">
  <pathelement location="${classes.dir}"/>
  <fileset dir="${lib.dir}">
    <include name="**/*.jar"/>
  </fileset>
</path>
...
<target name="_create db-schema" description="Creates the database schema by using the mapping documents">
  <echo message="The database schema will be created related by the hibernate mapping..." level="info"/>
  <taskdef name="schemaexport"
                classname="org.hibernate.tool.hbm2ddl.SchemaExportTask"
                classpathref="lib.class.path" />

  <!-- the following element throws the error -->
  <schemaexport config="${classes.dir}/hibernate.cfg.xml"
                          quiet="no"
                          text="yes"
                          drop="no"
                          delimiter=";"
                          output="${sql.dir}/${schema.name}.sql" />

  <echo message="Done." level="info"/>
</target>
...


The lib dir contains:

Code:
antlr-2.7.6.jar
asm-attrs.jar
asm.jar
backport-util-concurrent.jar
cfgatewayadapter.jar
cglib-2.1.3.jar
commons-codec-1.3.jar
commons-collections-3.1.jar
commons-httpclient-3.0.1.jar
commons-logging.jar
concurrent.jar
dom4j-1.6.1.jar
flex-messaging-common.jar
flex-messaging-core.jar
flex-messaging-opt.jar
flex-messaging-proxy.jar
flex-messaging-remoting.jar
freemarker.jar
hibernate-cglib-repack-2.1_3.jar
hibernate-tools.jar
hibernate3.jar
hsqldb.jar
javassist-3.4.GA.jar
jta-1.1.jar
log4j-1.2.15.jar
mysql-connector-java-5.1.7-bin.jar
slf4j-api-1.5.5.jar
slf4j-log4j12-1.5.5.jar
spring.jar
xalan.jar


The classes folder contains:

Code:
...
com/project/service/hibernate/Country.hbm.xml
com/project/service/hibernate/Language.hbm.xml
com/project/service/hibernate/Location.hbm.xml
com/project/service/hibernate/User.hbm.xml
...
hibernate.cfg.xml
log4j.properties
...


Because the classpath looks ok, I checked the mapping inside of hibernate.cfg.xml:

Code:
...
<hibernate-configuration>
  <session-factory>
    ...
    <mapping resource="com/project/service/hibernate/Country.hbm.xml" />
    <mapping resource="com/project/service/hibernate/Language.hbm.xml" />
    <mapping resource="com/project/service/hibernate/User.hbm.xml" />
    <mapping resource="com/project/service/hibernate/Location.hbm.xml" />
      
  </session-factory>
</hibernate-configuration>


The needed libs are referenced from my ANT HOME and other tasks like the generation of the POJOs with org.hibernate.tool.ant.HibernateToolTask works fine.
I tried alternative paths and I searched in forums and tutorials. I found some threads that handles similar problems, but I don't found a way to solve my issue.

- I am sure that the classpath is correct, so which other reasons could be there?
- Do anybody see a misstake in my config?
- Is there a version conflict of my libs?

I don't have more ideas what to do, please help me...

Thx a lot,
frustrated Nepumuk


Top
 Profile  
 
 Post subject: Solved
PostPosted: Wed Nov 19, 2008 7:14 am 
Newbie

Joined: Sun Nov 16, 2008 8:28 pm
Posts: 14
Location: Hamburg
Hi,

I solved the problem with a hibernate.properties file for the db-settings instead of define the connection settings inside the hibernate.cfg.xml.

The schema export task will be informed only about the properties file and a fileset tag inside the task includes all hbm.xml files inside the classes dir.

In this way the export works fine.

Regards,
Nepumuk


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 7:29 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
but this error has nothing to do with connection settings....

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 10:08 am 
Newbie

Joined: Sun Nov 16, 2008 8:28 pm
Posts: 14
Location: Hamburg
Yes, u are right. The connection settings in the hibernate properties are similar to the settings defined in the xml. The api doc defines that both ways are valid (xml properties overwrites the property file).

The point that fixed this issue is that I changed the call to the schema export task. The hibernate.cfg.xml will not passed to the task. Instead the properties will be given and a fileset of the hbm.xml files.

I think the explicit given hbm.xml file paths are the way to fix the problem.

Code:
  <schemaexport properties="${classes.dir}/hibernate.properties"
                          quiet="no"
                          text="yes"
                          drop="no"
                          delimiter=";"
                          output="${sql.dir}/${schema.name}.sql" >
    <fileset dir="${dir.classes}" includes="**/*.hbm.xml"/>
  </schemaexport>


Regards,
Nepumuk


Last edited by nepumuk on Wed Nov 19, 2008 12:12 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 10:26 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
that sounds like a bug then ;(

Have you tried the <hibernatetool> task from Hibernate tools in which the classloading is at least tested to work ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 11:54 am 
Newbie

Joined: Sun Nov 16, 2008 8:28 pm
Posts: 14
Location: Hamburg
Yes, I use the <hibernatetool> task to generate the POJOs. This task works well with the given classpath. There are no problems with the <hibernatetool> task.

Only the schema export task doesn't find the mapping files at the locations descriped in hibernate.cfg.xml.

Have a nice day...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 12:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
if you juse <hibernatetool> why not use its <hbm2ddll> which is the same as calling schemaexport but within the working classloader ? :)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 2:38 pm 
Newbie

Joined: Sun Nov 16, 2008 8:28 pm
Posts: 14
Location: Hamburg
Yea, I checked the <hibernatetool> task possibilities. Theese looks very nice. I will test if it will working.

Sounds very nice - thx...


Top
 Profile  
 
 Post subject: GREAT SOLVING
PostPosted: Wed Nov 19, 2008 5:05 pm 
Newbie

Joined: Sun Nov 16, 2008 8:28 pm
Posts: 14
Location: Hamburg
Very great, u are right. The <hibernatetool> Task works very fine. Now I can use annotations without an EJB-container and can garbage all hbm.xml files.

build.xml:
Code:
...
  <taskdef name="hibernatetool"
                classname="org.hibernate.tool.ant.HibernateToolTask"
                classpathref="lib.class.path"/>
   
  <target name="db-schema" description="Creates a SQL schema regarding on the mapped Java POJOs.">
    <hibernatetool destdir="${sql.dir}">
      <classpath>
        <path location="${classes.dir}"/>
      </classpath>
      <annotationconfiguration configurationfile="${classes.dir}/hibernate.cfg.xml"/>
      <hbm2ddl export="false" outputfilename="${schema.name}.sql"/>
    </hibernatetool>
  </target>
...


hibernate.cfg.xml:
Code:
<hibernate-configuration>
  <session-factory>
...
    <!-- mapping files -->
    <mapping class="com.project.service.data.Country"/>
    <mapping class="com.project.service.data.Language"/>
    <mapping class="com.project.service.data.User"/>
    <mapping class="com.project.service.data.Location"/>
...      
  </session-factory>
</hibernate-configuration>


Thx a lot, I am happy with hibernate ;-)!

Cheers...
Nepumuk


Top
 Profile  
 
 Post subject: Re: schema export ant task
PostPosted: Tue Jul 20, 2010 8:52 am 
Newbie

Joined: Tue Jul 20, 2010 8:35 am
Posts: 1
I know this is an old post, but as Manning's Hibernate Quickly by Patrick Peak still seems to be a major starting point for Hibernate learners, so couldn't help replying as I faced the same problem.

I think the problem is caused by: mixing source and build directories specified in:
-- the fileset element for including mappings
and,
-- the properties / config attributes of schemaexport for
changing both the above to the build directory fixed it for me.
Code:
   <target name="schema-export" depends="compile">

      <taskdef name="schemaexport"
         classname="org.hibernate.tool.hbm2ddl.SchemaExportTask"
         classpathref="hibernate.libs"
      />

      <schemaexport properties="${build}/hibernate.properties"
         quiet="no"
         text="yes"
         delimiter=";"
         output="schema-export.sql">
         <fileset dir="${build}" includes="**/*.hbm.xml"/>
      </schemaexport>

   </target>


now i get the schema output, but it still doesn't seem to reflect in the db :P

Code:
schema-export:
[schemaexport] log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
[schemaexport] log4j:WARN Please initialize the log4j system properly.
[schemaexport] alter table event drop foreign key FK5C6729ADC299D81;
[schemaexport] alter table family drop foreign key FKB3985B6449127AE1;
[schemaexport] drop table if exists contact;
[schemaexport] drop table if exists event;
[schemaexport] drop table if exists family;
[schemaexport] drop table if exists message;
[schemaexport] create table contact (id integer not null auto_increment, first_name varchar(255), last_name varchar(255), email varchar(255), primary
key (id));
[schemaexport] create table event (id integer not null auto_increment, name varchar(255), message_id integer, primary key (id));
[schemaexport] create table family (id integer not null auto_increment, first_name varchar(255), last_name varchar(255), relationship varchar(255), bd
ay date, interests varchar(255), contact_id integer, primary key (id));
[schemaexport] create table message (id integer not null auto_increment, msgSalutation varchar(255), msgBody varchar(255), msgSignoff varchar(255), pr
imary key (id));
[schemaexport] alter table event add index FK5C6729ADC299D81 (message_id), add constraint FK5C6729ADC299D81 foreign key (message_id) references messag
e (id);
[schemaexport] alter table family add index FKB3985B6449127AE1 (contact_id), add constraint FKB3985B6449127AE1 foreign key (contact_id) references con
tact (id);

BUILD SUCCESSFUL
Total time: 2 seconds


-- found out why schema is not reflecting in MySQL: MySQL schema export drop foreign key statements prevent table creation. Jeepers! http://opensource.atlassian.com/projects/hibernate/browse/HB-1422


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 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.