论坛首页 Java企业应用论坛

Hibernate 的SchemaExportTask问题

浏览 4658 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2004-04-05  
同一目录下已存在了.class文件和.hbm.xml配置文件。而且代码中使用SchemaExport也创建数据库成功,但在使用Ant是回报如下错误,莫名其妙 :-(,文件明明在啊。
-------------------------------------------------------------------------------------------
[schemaexport] BUILD FAILED: file:D:/ViadorPortal/webapps/viador-security/src/build.xml:221: Schema text failed: net.sf.hibernate.MappingException: persistent class [com.viador.portal.security.acl.orm.AclPeer] not found
-------------------------------------------------------------------------------------------
Ant Task 代码:
--------------------------------------------------------------------------------------------
<taskdef
name="portletdoclet"
classname="xdoclet.modules.portlet.PortletDocletTask"
classpathref="portal.class.path"
/>
  <!-- =================================================================== -->
  <!-- Compiles all the classes                                            -->
  <!-- =================================================================== -->
  <target name="export" depends="hibernate,compile">

  <echo>+---------------------------------------------------+</echo>
  <echo>|                                                   |</echo>
  <echo>| H I B E R N A T E   S C H E M A                   |</echo>
  <echo>|                                                   |</echo>
  <echo>+---------------------------------------------------+</echo>

  <schemaexport
  properties="${portal.security.web-inf.dir}/hibernate.properties"
  quiet="no"
  text="no"
  drop="no"
  delimiter=";"
  output="${portal.security.web-inf.dir}/schema-export.sql">
  <fileset dir="${portal.security.classes.dir}">
  <include name="com/viador/portal/security/acl/orm/*.hbm.xml"/>
  </fileset>
  </schemaexport>
  </target>
--------------------------------------------------------------------------------------------
已通过的Java代码:
--------------------------------------------------------------------------------------------
package com.hingesoftware.portal.orm.utils;

import com.hingesoftware.portal.orm.AclPeer;
import com.hingesoftware.portal.orm.CompanyPeer;
import com.hingesoftware.portal.orm.DepartmentPeer;
import com.hingesoftware.portal.orm.GroupPeer;
import com.hingesoftware.portal.orm.UserGroupLinkPeer;
import com.hingesoftware.portal.orm.UserPeer;
import net.sf.hibernate.MappingException;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.tool.hbm2ddl.SchemaExport;

public class HibernateUtil {

public static void main(String[] args) throws Exception {
Configuration con = new HibernateUtil().getConfiguration();
SessionFactory fac = con.buildSessionFactory();
new SchemaExport(con).create(true, true);
}

public Configuration getConfiguration() {
Configuration con = new Configuration();
try {
con.addClass(AclPeer.class);
con.addClass(CompanyPeer.class);
con.addClass(DepartmentPeer.class);
con.addClass(GroupPeer.class);
con.addClass(UserGroupLinkPeer.class);
con.addClass(UserPeer.class);
}
catch (MappingException ex) {
ex.printStackTrace(System.err);
}
return con;
}
}
--------------------------------------------------------------------------------------------
郁闷啊.............................
   发表时间:2004-04-05  
把你的应用(包括xml和class)打个jar包,放在taskdef schemaexport 的classpath里。
再试一下。
0 请登录后投票
   发表时间:2004-04-05  
谢谢你,我试了一下。报了一个新的错误信息
-------------------------------------------------------------------------------
[schemaexport] BUILD FAILED: file:D:/ViadorPortal/webapps/viador-security/src/build.xml:221: Schema text failed: org.dom4j.DocumentException: Error on line 1 of document  : 缺少文件根组件。 Nested exception: 缺少文件根组件。
-------------------------------------------------------------------------------
可能是什么错误呢?!
0 请登录后投票
   发表时间:2004-04-05  
对不起,刚才的错误是我改了配置文件以后出现的,我又恢复了一下。
还是老样子,没有任何改变,郁闷死我了 
0 请登录后投票
   发表时间:2004-04-05  
不太清楚,这是我的build文件。

<project name="queryexamples" default="schemaexport">

    <description>Hibernate Articles: Query Examples</description>

    <!-- Global -->
    <property name="classes" location="classes"/>
    <property name="lib" location="lib"/>
    <property name="src" location="src"/>

    <!-- SchemaExport -->
    <property name="mapping.files" location="${classes}/Cat.hbm.xml"/>

    <property name="db.dialect"
              value="net.sf.hibernate.dialect.PostgreSQLDialect"
     />
    <property name="db.driver" value="org.postgresql.Driver"/>
    <property name="db.url" value="jdbc:postgresql://localhost/querytest"/>
    <property name="db.user" value="turintest"/>
    <property name="db.password" value="seven11"/>

    <path id="class.path">
        <fileset dir="dist">
            <include name="*.*" />
        </fileset>

        <fileset dir="D:\JavaTool\hibernate-2.1\lib">
            <include name="*.*" />
        </fileset>

        <fileset dir="D:\JavaTool\hibernate-tools\lib">
            <include name="*.*" />
        </fileset>

        <fileset dir="D:\JavaTool\DevLib\JDBC">
            <include name="*.*" />
        </fileset>
    </path>

    <target name="jar">
        <jar jarfile="dist/bin.jar" basedir="bin" >
            <include name="**/*.*"/>
        </jar>
    </target>

    <target name="schemaexport" depends="jar">
        <taskdef name="schemaexport"
        classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"
        classpathref="class.path"/>

        <schemaexport
        properties="hibernate.properties"
        quiet="no"
        text="no"
        drop="no"
        delimiter=";"
        output="schema-export.sql">
            <fileset dir="src">
                <include name="**/Cat.hbm.xml"/>
            </fileset>
        </schemaexport>
    </target>

</project>
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics