-->
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.  [ 9 posts ] 
Author Message
 Post subject: Problem with SchemaExport
PostPosted: Sun Jan 04, 2004 8:47 pm 
Beginner
Beginner

Joined: Tue Dec 30, 2003 1:51 pm
Posts: 49
Location: Michigan, USA
Hello -
I am new to hibernate and have been working through the docs and trying things as I go. I have gotten hibernate 2.1 setup with jBoss 3.2.2 as in 66.html and have added the xdoclet tags and ant tasks.

When running the hibernateSar target it generates the *.hbm.xml correctly. However, when the schemaexport runs it blows up. I have the ant scripts and output below


Code:
<!-- =================================================================== -->
   <!-- generates the hibernate HBM.XML files and SAR descriptor             -->
   <!-- =================================================================== -->

   <target name="hibernate" description="Generates Hibernate class descriptor files." depends="build">

      <taskdef name="hibernatedoclet" classname="xdoclet.modules.hibernate.HibernateDocletTask">
         <classpath>
            <fileset dir="${custom.lib}">
               <include name="*.jar" />
               <include name="xdoclet-1.2b4.jar" />
               <include name="xdoclet-hibernate-module-1.2b4.jar" />
               <include name="xdoclet-xdoclet-module-1.2b4.jar" />
               <include name="xjavadoc-1.0.jar" />
            </fileset>
         </classpath>
      </taskdef>
      
      <!-- Execute the hibernatedoclet task -->
      <hibernatedoclet destdir="${build.resources}/sar/hibernate"
                     excludedtags="@version,@author,@todo,@see,@desc"
                     addedtags="@xdoclet-generated at ${TODAY}@copyright foobar, Inc.,@author Jason Pratt,@version ${version}"
                     force="${xdoclet.force}"
                     mergedir="${build.resources}/sar/hibernate"
                     verbose="true">

         <fileset dir="${src.dir}">
            <include name="**/*.java" />
         </fileset>

         <hibernate version="2.0" />

         <jbossservice destdir="${jboss.dir}"
                     serviceName="Hibernate"
                     jndiName="${hibernate.jndi.name}"
                     dataSource="${hibernate.datasource.name}"
                     dialect="${hibernate.dialect}"
                     useOuterJoin="true"
                     transactionManagerStrategy="net.sf.hibernate.transaction.JBossTransactionManagerLookup"
                     transactionStrategy="net.sf.hibernate.transaction.JTATransactionFactory"
                     userTransactionName="UserTransaction" />

      </hibernatedoclet>

   </target>
   
      <!-- =================================================================== -->
   <!-- Hibernate SAR build                                                 -->
   <!-- =================================================================== -->

   <target name="hibernateSar" depends="hibernate">

      <jar destfile="${jboss.dir}/hibernateStartup.sar">

         <!-- Get the generated hbm.xml files  -->
         <fileset dir="${build.resources}/sar/hibernate">
            <include name="**/*.hbm.xml" />
         </fileset>
         <fileset dir="${custom.lib}">
            <include name="dom4j.jar"/>
            <include name="ehcache.jar"/>
         </fileset>
         <metainf dir="${jboss.dir}">
            <include name="jboss-service.xml" />
         </metainf>
      </jar>

      <!--  Generate a schema DDL  -->
      <antcall target="hibernate_schemaexport" />   

   </target>

   <!-- =================================================================== -->
   <!-- Generate the database creation scripts from the Hibernate schema.   -->
   <!-- =================================================================== -->
   <target name="hibernate_schemaexport">
      <taskdef name="schemaexport" classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask">
         <classpath>
            <fileset dir="${hibernate}">
               <include name="hibernate2.jar" />
            </fileset>
            <fileset dir="${hibernate}/lib">
               <include name="cglib-asm.jar" />
               <include name="commons-collections.jar" />
               <include name="commons-beanutils.jar" />
               <include name="commons-lang.jar" />
               <include name="commons-logging.jar" />
               <include name="dom4j.jar" />
               <include name="jaas.jar" />
               <include name="jcs.jar" />
               <include name="jdbc2_0-stdext.jar" />
               <include name="dom4j.jar" />
               <include name="jaas.jar" />
               <include name="jcs.jar" />
               <include name="jdbc2_0-stdext.jar" />
               <include name="odmg.jar" />
            </fileset>
            <fileset dir="${jboss.dir}">
               <include name="hibernateStartup.sar" />
            </fileset>
         </classpath>
      </taskdef>

      <echo message="drop-build.sql"/>
      
      <schemaexport output="${mysql.dir}/drop-and-build.sql"
                  properties="${hibernate.props}"
                  quiet="yes"
                  delimiter=";"
                  text="yes">
                  
         <!-- -->
         <fileset dir="${build.resources}/sar/hibernate">
            <include name="**/*.hbm.xml" />
         </fileset>
         
      </schemaexport>

      <echo message="drop.sql"/>

      <schemaexport output="${mysql.dir}/drop.sql"
                  properties="${hibernate.props}"
                  quiet="yes"
                  drop="yes"
                  delimiter=";"
                  text="yes">
                  
         <fileset dir="${build.resources}/sar/hibernate">
            <include name="**/*.hbm.xml" />
         </fileset>
      </schemaexport>

   </target>


The output is

Code:
Buildfile: build.xml

init:

hibernate:
[hibernatedoclet] (XDocletMain.start                   47  ) Running <hibernate/>
[hibernatedoclet] Generating mapping file for omni.user.UserBean.
[hibernatedoclet]    omni.user.UserBean
[hibernatedoclet] Generating mapping file for omni.user.AddressBean.
[hibernatedoclet]    omni.user.AddressBean
[hibernatedoclet] Generating mapping file for omni.user.ProfileBean.
[hibernatedoclet]    omni.user.ProfileBean
[hibernatedoclet] (XDocletMain.start                   47  ) Running <jbossservice/>
[hibernatedoclet] Generating jboss service descriptor

hibernateSar:
      [jar] Building jar: F:\projects\jboss\hibernateStartup.sar

hibernate_schemaexport:
     [echo] drop-build.sql
[schemaexport] Jan 4, 2004 7:24:42 PM net.sf.hibernate.cfg.Environment <clinit>
[schemaexport] INFO: Hibernate 2.1 final
[schemaexport] Jan 4, 2004 7:24:42 PM net.sf.hibernate.cfg.Environment <clinit>
[schemaexport] INFO: hibernate.properties not found
[schemaexport] Jan 4, 2004 7:24:42 PM net.sf.hibernate.cfg.Environment <clinit>
[schemaexport] INFO: using CGLIB reflection optimizer
[schemaexport] Jan 4, 2004 7:24:42 PM net.sf.hibernate.cfg.Configuration addFile
[schemaexport] INFO: Mapping file: F:\projects\\build\resources\sar\hibernate\omni\user\AddressBean.hbm.xml
[schemaexport] Jan 4, 2004 7:24:43 PM net.sf.hibernate.cfg.Configuration add
[schemaexport] SEVERE: Could not compile the mapping document
[schemaexport] net.sf.hibernate.MappingException: persistent class [omni.user.AddressBean] not found
[schemaexport]  at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:81)
[schemaexport]  at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:207)
[schemaexport]  at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1167)
[schemaexport]  at net.sf.hibernate.cfg.Configuration.add(Configuration.java:245)
[schemaexport]  at net.sf.hibernate.cfg.Configuration.addFile(Configuration.java:167)
[schemaexport]  at net.sf.hibernate.tool.hbm2ddl.SchemaExportTask.getConfiguration(SchemaExportTask.java:186)
[schemaexport]  at net.sf.hibernate.tool.hbm2ddl.SchemaExportTask.execute(SchemaExportTask.java:132)
[schemaexport]  at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:193)
[schemaexport]  at org.apache.tools.ant.Task.perform(Task.java:341)
[schemaexport]  at org.apache.tools.ant.Target.execute(Target.java:309)
[schemaexport]  at org.apache.tools.ant.Target.performTasks(Target.java:336)
[schemaexport]  at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
[schemaexport]  at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:397)
[schemaexport]  at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:143)
[schemaexport]  at org.apache.tools.ant.Task.perform(Task.java:341)
[schemaexport]  at org.apache.tools.ant.Target.execute(Target.java:309)
[schemaexport]  at org.apache.tools.ant.Target.performTasks(Target.java:336)
[schemaexport]  at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
[schemaexport]  at org.apache.tools.ant.Project.executeTargets(Project.java:1255)
[schemaexport]  at org.apache.tools.ant.Main.runBuild(Main.java:609)
[schemaexport]  at org.apache.tools.ant.Main.start(Main.java:196)
[schemaexport]  at org.apache.tools.ant.Main.main(Main.java:235)
[schemaexport] Caused by: java.lang.ClassNotFoundException: omni.user.AddressBean
[schemaexport]  at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1075)
[schemaexport]  at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1036)
[schemaexport]  at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:925)
[schemaexport]  at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
[schemaexport]  at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
[schemaexport]  at java.lang.Class.forName0(Native Method)
[schemaexport]  at java.lang.Class.forName(Class.java:141)
[schemaexport]  at net.sf.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:75)
[schemaexport]  at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:78)
[schemaexport]  ... 21 more
[schemaexport] Jan 4, 2004 7:24:43 PM net.sf.hibernate.cfg.Configuration addFile
[schemaexport] SEVERE: Could not configure datastore from file: F:\build\resources\sar\hibernate\omni\user\AddressBean.hbm.xml
[schemaexport] net.sf.hibernate.MappingException: persistent class [omni.user.AddressBean] not found
[schemaexport]  at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:81)
[schemaexport]  at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:207)
[schemaexport]  at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1167)
[schemaexport]  at net.sf.hibernate.cfg.Configuration.add(Configuration.java:245)
[schemaexport]  at net.sf.hibernate.cfg.Configuration.addFile(Configuration.java:167)
[schemaexport]  at net.sf.hibernate.tool.hbm2ddl.SchemaExportTask.getConfiguration(SchemaExportTask.java:186)
[schemaexport]  at net.sf.hibernate.tool.hbm2ddl.SchemaExportTask.execute(SchemaExportTask.java:132)
[schemaexport]  at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:193)
[schemaexport]  at org.apache.tools.ant.Task.perform(Task.java:341)
[schemaexport]  at org.apache.tools.ant.Target.execute(Target.java:309)
[schemaexport]  at org.apache.tools.ant.Target.performTasks(Target.java:336)
[schemaexport]  at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
[schemaexport]  at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:397)
[schemaexport]  at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:143)
[schemaexport]  at org.apache.tools.ant.Task.perform(Task.java:341)
[schemaexport]  at org.apache.tools.ant.Target.execute(Target.java:309)
[schemaexport]  at org.apache.tools.ant.Target.performTasks(Target.java:336)
[schemaexport]  at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
[schemaexport]  at org.apache.tools.ant.Project.executeTargets(Project.java:1255)
[schemaexport]  at org.apache.tools.ant.Main.runBuild(Main.java:609)
[schemaexport]  at org.apache.tools.ant.Main.start(Main.java:196)
[schemaexport]  at org.apache.tools.ant.Main.main(Main.java:235)
[schemaexport] Caused by: java.lang.ClassNotFoundException: omni.user.AddressBean
[schemaexport]  at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1075)
[schemaexport]  at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1036)
[schemaexport]  at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:925)
[schemaexport]  at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
[schemaexport]  at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
[schemaexport]  at java.lang.Class.forName0(Native Method)
[schemaexport]  at java.lang.Class.forName(Class.java:141)
[schemaexport]  at net.sf.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:75)
[schemaexport]  at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:78)
[schemaexport]  ... 21 more


I do not understand this section, I mean I do understand what is says but not why it is saying it.

Code:
[schemaexport] Jan 4, 2004 7:24:42 PM net.sf.hibernate.cfg.Configuration addFile
[schemaexport] INFO: Mapping file: F:\build\resources\sar\hibernate\omni\user\AddressBean.hbm.xml
[schemaexport] Jan 4, 2004 7:24:43 PM net.sf.hibernate.cfg.Configuration add
[schemaexport] SEVERE: Could not compile the mapping document
[schemaexport] net.sf.hibernate.MappingException: persistent class [omni.user.AddressBean] not found


Do I still need to have a config file since I set it up as a jboss mbean for SchemaExport to work? Is it looking for the class in the same place as the hbm? The docs a very vague on how this works.

Any ideas of what I should look at or where?

regards,

Jason


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 04, 2004 9:01 pm 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
You need to include the class files for your omni.user.*.java files in the classpath for the schemaexport task, ie. whereever you compiled ${src.dir}/**/*.java to.

You could include those class files in the hibernate.sar. The example in 66.html does not due to EAR classpath issues.

You need a hibernate.properties for the schemaexport, because the DDL generated by schemaexport is SQL dialect specific, and the schemaexport also starts up a Hibernate instance in order to have access to all the required metadata.


Sherman


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 05, 2004 12:32 pm 
Beginner
Beginner

Joined: Tue Dec 30, 2003 1:51 pm
Posts: 49
Location: Michigan, USA
wicked - thanks sherman

jason


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 05, 2004 1:01 pm 
Beginner
Beginner

Joined: Tue Dec 30, 2003 1:51 pm
Posts: 49
Location: Michigan, USA
just tried it with a link to where my *.class files are and a props file, the output is the same.

it is still complaining about

Code:
[schemaexport] SEVERE: Could not compile the mapping document
[schemaexport] net.sf.hibernate.MappingException: persistent class [omni.user.AddressBean] not found


this is very frustrating. any ideas.


jason


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 05, 2004 3:25 pm 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
A link may not work.

Make sure that the classes are on the classpath by running Ant with verbose tracing.


Sherman


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 05, 2004 6:30 pm 
Beginner
Beginner

Joined: Tue Dec 30, 2003 1:51 pm
Posts: 49
Location: Michigan, USA
okay i turned it on, the classes are in the path. i am getting the following

Code:
[schemaexport] (cfg.Environment                     481 ) using CGLIB reflection optimizer
[schemaexport] (cfg.Configuration                   164 ) Mapping file: F:\projects\omni_website\omni-sys.us\build\omni\user\AddressBean.class
[schemaexport] (util.XMLHelper                      48  ) Error parsing XML: F:\projects\omni_website\omni-sys.us\build\omni\user\AddressBean.class(1) Content is not allowed in prolog.
[schemaexport] (cfg.Configuration                   172 ) Could not configure datastore from file: F:\projects\omni_website\omni-sys.us\build\omni\user\AddressBean.class
[schemaexport] org.dom4j.DocumentException: Error on line 1 of document  : Content is not allowed in prolog. Nested exception: Content is not allowed in prolog.
[schemaexport]  at org.dom4j.io.SAXReader.read(SAXReader.java:355)
[schemaexport]  at org.dom4j.io.SAXReader.read(SAXReader.java:219)
[schemaexport]  at net.sf.hibernate.cfg.Configuration.addFile(Configuration.java:167)


here is the hbm file that xdoclet is generating

Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class
        name="omni.user.AddressBean"
        table="address"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="id"
            type="long"
            length=""
            unsaved-value="null"
        >
            <generator class="native">
            </generator>
        </id>

        <property
            name="city"
            type="String"
            update="true"
            insert="true"
            column="city"
            not-null="false"
            unique="false"
        />

        <property
            name="country"
            type="String"
            update="true"
            insert="true"
            column="country"
            not-null="false"
            unique="false"
        />

        <property
            name="state"
            type="String"
            update="true"
            insert="true"
            column="state"
            not-null="false"
            unique="false"
        />

        <property
            name="street"
            type="String"
            update="true"
            insert="true"
            column="street"
            not-null="false"
            unique="false"
        />

        <property
            name="street2"
            type="String"
            update="true"
            insert="true"
            column="street2"
            not-null="false"
            unique="false"
        />

        <property
            name="zip"
            type="int"
            update="true"
            insert="true"
            column="zip"
            not-null="false"
            unique="false"
        />

        <property
            name="zipPlus4"
            type="int"
            update="true"
            insert="true"
            column="zipPlus4"
            not-null="false"
            unique="false"
        />


    </class>

</hibernate-mapping>


What does it mean by prolog? this is really frustrating.

jason


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 05, 2004 6:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You got schemaexport to work on your class files somehow, not on your mapping XML files


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 05, 2004 6:44 pm 
Beginner
Beginner

Joined: Tue Dec 30, 2003 1:51 pm
Posts: 49
Location: Michigan, USA
oh, man I found it right after i posted it.
this is so lame, i have to call ALL of the files for it to work correctly

Code:
<schemaexport output="${mysql.dir}/drop-and-build.sql"          
         properties="hibernate.properties"
         quiet="no"
         delimiter=";"
         text="yes">

         <fileset dir="${build.dir}">
            <include name="**/AddressBean.hbm.xml" />
            <include name="**/UserBean.hbm.xml" />
            <include name="**/ProfileBean.hbm.xml" />
            <include name="**/AddressBean.class" />
            <include name="**/UserBean.class" />
            <include name="**/ProfileBean.class" />
         </fileset>
      </schemaexport>


whereas before i was using **/*.hbm.xml for the hibernate mappings.
somebody must have a better ant task for this

thanks guys for the help


jason


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 05, 2004 7:37 pm 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
Still not right.

Should be:

<taskdef name="schemaexport" classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask">
<classpath>
<fileset dir="${hibernate}">
<-- Hibernate JARs -->
</fileset>
<fileset dir="${hibernate}/lib">
<-- Hibernate JARs -->
</fileset>
<fileset dir="${jboss.dir}">
<include name="hibernateStartup.sar" />
</fileset>
<pathelement location="${build.dir}"/>
</classpath>
</taskdef>

And

Code:

<schemaexport output="${mysql.dir}/drop-and-build.sql"          
         properties="hibernate.properties"
         quiet="no"
         delimiter=";"
         text="yes">
   <fileset dir="${build.dir}">
      <include name="**/*.hbm.xml" />
   </fileset>
</schemaexport>


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