문제

Hibernate.cfg.xml 파일의 동일한 폴더에 배치되는 *.hbm.xml 파일이 있습니다. 이제이 폴더의 하위 폴더에있는 다른 *.hbm.xml 파일을 매핑하고 싶습니다. 어떻게 할 수 있습니까? 감사!

여기 내 부분이 있습니다 hibernate.cfg.xml:

   <hibernate-configuration>
        <session-factory name="MySessionFactory">
             <!-- some hibernate properties here --> 

             <!--This below works fine-->
             <mapping resource="A.hbm.xml"/>

             <!--This doesn't-->
             <mapping resource="/dir/B.hbm.xml"/>

        </session-factory>
   </hibernate-configuration>

이것은 내 개미 파일의 일부입니다.

        <target name="generateHibernateSql">

        <taskdef name="SchemaExportTask"
            classname="org.hibernate.tool.hbm2ddl.SchemaExportTask"
        >
            <classpath>
                <pathelement location="${build.classes.main.dir}"/>
                <pathelement location="${base.configuration.hibernate.dir}"/>
                <path refid="build.classpath.lib"/>
            </classpath>
        </taskdef>

여기 내 폴더 구조가 있습니다

${base.configuration.hibernate.dir}
   | hibernate.cfg.xml
   | A.hbm.xml
   |--dir
   |---| B.hbm.xml
${build.classes.main.dir}



편집하다

Maurice가 제안한대로 처음 시도하고 실패했습니다.

 <mapping resource="dir/B.hbm.xml"/>

여전히 동일한 오류를 제공합니다.

Schema text failed: Could not parse mapping document from resource dir/B.hbm.xml

그리고 Mark가 제안한대로 Schemeexpoert에 추가하려고 계속했습니다. 그러면 더 이상 내 "a.hbm.xml"도 찾지 못할 것입니다. 오류 제공 :

Schema text failed: Could not parse mapping document from resource A.hbm.xml

내 schemaexporttask는 이제 다음과 같습니다.

        <SchemaExportTask
            config="${base.configuration.hibernate.dir}\hibernate.cfg.xml"
            quiet="no"
            text="no"
            drop="no"
            delimiter=";"
            create="yes"
            output="${dist.database.dir}\schema-export.sql"
        >
            <fileset dir="${base.configuration.hibernate.dir}">
                <include name="**/*.hbm.xml"/>
            </fileset>
        </SchemaExportTask>



해결

결론은 내가 정말 바보 였다는 것입니다. 다른 디렉토리에있는 것과는 아무런 관련이 없었습니다. 한 번에 테스트 단계에 두 가지를 바꾸고 있었기 때문에 혼란스러워서 무고한 "디렉토리 변경"에서 모든 것을 비난했습니다. 모두의 시간을 낭비해서 죄송합니다.

누구든지 관심이 있다면 여기에 무슨 일이 일어났습니다. 로컬 DTD 파일을 사용하여 XSLT 번역을 수행했으며 XSL 파일에 상대 경로가있는 로컬 DTD 파일을 지정했습니다. 그러나 생성 된 hbm.xml 파일을 차이 디렉토리에 넣습니다. 따라서 SchemaExportTask는 더 이상 DTD 파일을 찾을 수 없으며 새 HBM.XML 파일을 구문 분석하지 못했습니다. 그리고 어리석은 이유 때문에, 나는 다음과 같은 완전히 다른 오류 메시지가 같은 것을 의미한다고 생각했습니다 .... 사람들이 정당한 이유로 오류 메시지를 썼다는 것을 상기시켜 주셔서 감사합니다! 첨가 fileset 아직도 작동하지 않지만 이제 오류 측정 값을 읽는 것을 알고 있습니다 ... 곧 고칠 것이라고 확신합니다. =. = '' '

Schema text failed: resource: B.hbm.xml not found
Schema text failed: Could not parse mapping document from resource dir/B.hbm.xml
도움이 되었습니까?

해결책

일반 최대 절전 모드 사용에 대해서는 Maurice가 제안한 변화에 동의하지만 더 많은 설명을 할 것이라고 생각했습니다. 최대 절전 모드 매핑 파일은 클래스 경로의 리소스로로드됩니다. 클래스 경로에 $ {base.configuration.hibernate.dir}가 있으므로 이에 대한 매핑 파일의 경로를 제공해야하므로 전면 /를 제거해야합니다.

Ant의 스키마 내보내기 도구를 사용합니다 문서 매핑 파일을 클래스 경로에서 찾을 것으로 기대하기보다는 파일 세트로 정의해야한다고 가정 해보십시오. 보다

다른 팁

<mapping resource="dir/B.hbm.xml"/>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top