Ant não exporta o schema pelo Hibernate

1 resposta
juninhodg

bom dia! Estou utilizando um script do ant para exportar o schema de uma base de dados. Sigo o exemplo do livro Java Persistence with Hibernate mas tive que adaptar pois sua versão do framework é 3.2, e eu uso a 4.1.7 final. No console, o seguinte erro é mostrado:

Buildfile: D:\Projetos Eclipse\Hello World Hibernate\build.xml

clean:
[delete] Deleting directory D:\Projetos Eclipse\Hello World Hibernate\bin
[mkdir] Created dir: D:\Projetos Eclipse\Hello World Hibernate\bin

compile:
[javac] D:\Projetos Eclipse\Hello World Hibernate\build.xml:39: warning: ‘in
cludeantruntime’ was not set, defaulting to build.sysclasspath=last; set to fals
e for repeatable builds
[javac] Compiling 3 source files to D:\Projetos Eclipse\Hello World Hibernat
e\bin

copymetafiles:
[copy] Copying 4 files to D:\Projetos Eclipse\Hello World Hibernate\bin

schemaexport:

[schemaexport] Nov 01, 2012 10:34:42 AM org.hibernate.annotations.common.Version

<clinit>

[schemaexport] INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}

[schemaexport] Nov 01, 2012 10:34:42 AM org.hibernate.Version logVersion

[schemaexport] INFO: HHH000412: Hibernate Core {4.1.7.Final}

[schemaexport] Nov 01, 2012 10:34:42 AM org.hibernate.cfg.Environment <clinit>

[schemaexport] INFO: HHH000206: hibernate.properties not found

[schemaexport] Nov 01, 2012 10:34:42 AM org.hibernate.cfg.Environment buildBytec

odeProvider

[schemaexport] INFO: HHH000021: Bytecode provider name : javassist

[schemaexport] Nov 01, 2012 10:34:42 AM org.hibernate.cfg.Configuration addFile

[schemaexport] INFO: HHH000220: Reading mappings from file: D:\Projetos Eclipse

Hello World Hibernate\src\hello\Message.hbm.xml

[schemaexport] Nov 01, 2012 10:34:42 AM org.hibernate.dialect.Dialect <init>

[schemaexport] INFO: HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect

BUILD FAILED
D:\Projetos Eclipse\Hello World Hibernate\build.xml:77: Schema text failed: Coul
d not parse mapping document from file D:\Projetos Eclipse\Hello World Hibernate
\src\hello\Message.hbm.xml

Total time: 1 second

D:\Projetos Eclipse\Hello World Hibernate>

Achei o erro muito genérico, não consegui identificar aonde o problema começa, só que parece que ele não pode analisar o arquivo Message.hbm.xml

1 Resposta

juninhodg

Pesquisei um pouco e habilitei o log do ant… ele gerou o seguinte arquivo:

Detected Java version: 1.7 in: C:\Program Files (x86)\Java\jdk1.7.0_01\jre
Detected OS: Windows 7
parsing buildfile D:\Projetos Eclipse\Hello World Hibernate\build.xml with URI = file:/D:/Projetos%20Eclipse/Hello%20World%20Hibernate/build.xml
Project base dir set to: D:\Projetos Eclipse\Hello World Hibernate
parsing buildfile jar:file:/D:/apache-ant-1.8.4/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/D:/apache-ant-1.8.4/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
Build sequence for target(s) `schemaexport’ is [clean, compile, copymetafiles, schemaexport]
Complete build sequence is [clean, compile, copymetafiles, schemaexport, dbmanager, run, ]

clean:
[delete] Deleting directory D:\Projetos Eclipse\Hello World Hibernate\bin
[delete] Deleting D:\Projetos Eclipse\Hello World Hibernate\bin\hello\HelloWorld.class
[delete] Deleting D:\Projetos Eclipse\Hello World Hibernate\bin\hello\Message.class
[delete] Deleting D:\Projetos Eclipse\Hello World Hibernate\bin\hello\Message.hbm.xml
[delete] Deleting directory D:\Projetos Eclipse\Hello World Hibernate\bin\hello
[delete] Deleting D:\Projetos Eclipse\Hello World Hibernate\bin\hibernate.cfg.xml
[delete] Deleting D:\Projetos Eclipse\Hello World Hibernate\bin\hibernate.properties
[delete] Deleting D:\Projetos Eclipse\Hello World Hibernate\bin\log4j.properties
[delete] Deleting D:\Projetos Eclipse\Hello World Hibernate\bin\persistence\HibernateUtil.class
[delete] Deleting directory D:\Projetos Eclipse\Hello World Hibernate\bin\persistence
[delete] Deleting directory D:\Projetos Eclipse\Hello World Hibernate\bin
[mkdir] Created dir: D:\Projetos Eclipse\Hello World Hibernate\bin

compile:
[mkdir] Skipping D:\Projetos Eclipse\Hello World Hibernate\bin because it already exists.
[javac] D:\Projetos Eclipse\Hello World Hibernate\build.xml:39: warning: ‘includeantruntime’ was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] hello\HelloWorld.java added as hello\HelloWorld.class doesn’t exist.
[javac] D:\Projetos Eclipse\Hello World Hibernate\src\hello\Message.hbm.xml skipped - don’t know how to handle it
[javac] hello\Message.java added as hello\Message.class doesn’t exist.
[javac] D:\Projetos Eclipse\Hello World Hibernate\src\hibernate.cfg.xml skipped - don’t know how to handle it
[javac] D:\Projetos Eclipse\Hello World Hibernate\src\hibernate.properties skipped - don’t know how to handle it
[javac] D:\Projetos Eclipse\Hello World Hibernate\src\log4j.properties skipped - don’t know how to handle it
[javac] persistence\HibernateUtil.java added as persistence\HibernateUtil.class doesn’t exist.
[javac] Compiling 3 source files to D:\Projetos Eclipse\Hello World Hibernate\bin
[javac] Using modern compiler
[javac] Compilation arguments:
[javac] ‘-nowarn’
[javac] ‘-d’
[javac] ‘D:\Projetos Eclipse\Hello World Hibernate\bin’
[javac] ‘-classpath’
[javac] ‘D:\Projetos Eclipse\Hello World Hibernate\bin;D:\Projetos Eclipse\Hello World Hibernate\lib\antlr-2.7.7.jar;D:\Projetos Eclipse\Hello World Hibernate\lib\dom4j-1.6.1.jar;D:\Projetos Eclipse\Hello World Hibernate\lib\hibernate-commons-annotations-4.0.1.Final.jar;D:\Projetos Eclipse\Hello World Hibernate\lib\hibernate-core-4.1.7.Final.jar;D:\Projetos Eclipse\Hello World Hibernate\lib\hibernate-jpa-2.0-api-1.0.1.Final.jar;D:\Projetos Eclipse\Hello World Hibernate\lib\hsqldb.jar;D:\Projetos Eclipse\Hello World Hibernate\lib\javassist-3.15.0-GA.jar;D:\Projetos Eclipse\Hello World Hibernate\lib\jboss-logging-3.1.0.GA.jar;D:\Projetos Eclipse\Hello World Hibernate\lib\jboss-transaction-api_1.1_spec-1.0.0.Final.jar;D:\apache-ant-1.8.4\lib\ant-launcher.jar;D:\Projetos Eclipse\Hello World Hibernate;C:\Program Files (x86)\Java\jdk1.7.0_01;D:\apache-ant-1.8.4\lib\ant-antlr.jar;D:\apache-ant-1.8.4\lib\ant-apache-bcel.jar;D:\apache-ant-1.8.4\lib\ant-apache-bsf.jar;D:\apache-ant-1.8.4\lib\ant-apache-log4j.jar;D:\apache-ant-1.8.4\lib\ant-apache-oro.jar;D:\apache-ant-1.8.4\lib\ant-apache-regexp.jar;D:\apache-ant-1.8.4\lib\ant-apache-resolver.jar;D:\apache-ant-1.8.4\lib\ant-apache-xalan2.jar;D:\apache-ant-1.8.4\lib\ant-commons-logging.jar;D:\apache-ant-1.8.4\lib\ant-commons-net.jar;D:\apache-ant-1.8.4\lib\ant-jai.jar;D:\apache-ant-1.8.4\lib\ant-javamail.jar;D:\apache-ant-1.8.4\lib\ant-jdepend.jar;D:\apache-ant-1.8.4\lib\ant-jmf.jar;D:\apache-ant-1.8.4\lib\ant-jsch.jar;D:\apache-ant-1.8.4\lib\ant-junit.jar;D:\apache-ant-1.8.4\lib\ant-junit4.jar;D:\apache-ant-1.8.4\lib\ant-netrexx.jar;D:\apache-ant-1.8.4\lib\ant-swing.jar;D:\apache-ant-1.8.4\lib\ant-testutil.jar;D:\apache-ant-1.8.4\lib\ant.jar;C:\Program Files (x86)\Java\jdk1.7.0_01\lib\tools.jar’
[javac] ‘-sourcepath’
[javac] ‘D:\Projetos Eclipse\Hello World Hibernate\src’
[javac] ‘-g:none’
[javac]
[javac] The ’ characters around the executable and arguments are
[javac] not part of the command.
[javac] Files to be compiled:
[javac] D:\Projetos Eclipse\Hello World Hibernate\src\hello\HelloWorld.java
[javac] D:\Projetos Eclipse\Hello World Hibernate\src\hello\Message.java
[javac] D:\Projetos Eclipse\Hello World Hibernate\src\persistence\HibernateUtil.java

copymetafiles:
[copy] hello\Message.hbm.xml added as hello\Message.hbm.xml doesn’t exist.
[copy] hibernate.cfg.xml added as hibernate.cfg.xml doesn’t exist.
[copy] hibernate.properties added as hibernate.properties doesn’t exist.
[copy] log4j.properties added as log4j.properties doesn’t exist.
[copy] No sources found.
[copy] Copying 4 files to D:\Projetos Eclipse\Hello World Hibernate\bin
[copy] Copying D:\Projetos Eclipse\Hello World Hibernate\src\hello\Message.hbm.xml to D:\Projetos Eclipse\Hello World Hibernate\bin\hello\Message.hbm.xml
[copy] Copying D:\Projetos Eclipse\Hello World Hibernate\src\hibernate.cfg.xml to D:\Projetos Eclipse\Hello World Hibernate\bin\hibernate.cfg.xml
[copy] Copying D:\Projetos Eclipse\Hello World Hibernate\src\hibernate.properties to D:\Projetos Eclipse\Hello World Hibernate\bin\hibernate.properties
[copy] Copying D:\Projetos Eclipse\Hello World Hibernate\src\log4j.properties to D:\Projetos Eclipse\Hello World Hibernate\bin\log4j.properties

schemaexport:

[schemaexport] Nov 01, 2012 3:18:44 PM org.hibernate.annotations.common.Version <clinit>

[schemaexport] INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}

[schemaexport] Nov 01, 2012 3:18:44 PM org.hibernate.Version logVersion

[schemaexport] INFO: HHH000412: Hibernate Core {4.1.7.Final}

[schemaexport] Nov 01, 2012 3:18:44 PM org.hibernate.cfg.Environment <clinit>

[schemaexport] INFO: HHH000206: hibernate.properties not found

[schemaexport] Nov 01, 2012 3:18:44 PM org.hibernate.cfg.Environment buildBytecodeProvider

[schemaexport] INFO: HHH000021: Bytecode provider name : javassist

[schemaexport] Nov 01, 2012 3:18:44 PM org.hibernate.cfg.Configuration addFile

[schemaexport] INFO: HHH000220: Reading mappings from file: D:\Projetos Eclipse\Hello World Hibernate\src\hello\Message.hbm.xml

[schemaexport] Nov 01, 2012 3:18:44 PM org.hibernate.dialect.Dialect <init>

[schemaexport] INFO: HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect
BUILD FAILED

D:\Projetos Eclipse\Hello World Hibernate\build.xml:77: Schema text failed: Could not parse mapping document from file D:\Projetos Eclipse\Hello World Hibernate\src\hello\Message.hbm.xml

at org.hibernate.tool.hbm2ddl.SchemaExportTask.execute(SchemaExportTask.java:173)

at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:601)

at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)

at org.apache.tools.ant.Task.perform(Task.java:348)

at org.apache.tools.ant.Target.execute(Target.java:392)

at org.apache.tools.ant.Target.performTasks(Target.java:413)

at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)

at org.apache.tools.ant.Project.executeTarget(Project.java:1368)

at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)

at org.apache.tools.ant.Project.executeTargets(Project.java:1251)

at org.apache.tools.ant.Main.runBuild(Main.java:811)

at org.apache.tools.ant.Main.startAnt(Main.java:217)

at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)

at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from file D:\Projetos Eclipse\Hello World Hibernate\src\hello\Message.hbm.xml

at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3415)

at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXmlQueue(Configuration.java:3404)

at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3392)

at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1341)

at org.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:931)

at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:188)

at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:156)

at org.hibernate.tool.hbm2ddl.SchemaExportTask.getSchemaExport(SchemaExportTask.java:242)

at org.hibernate.tool.hbm2ddl.SchemaExportTask.execute(SchemaExportTask.java:170)

 17 more

Caused by: org.hibernate.MappingException: class hello.Message not found while looking for property: id

at org.hibernate.internal.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:232)

at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:326)

at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:449)

at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:382)

at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:322)

at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:173)

at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3412)

 25 more

Caused by: java.lang.ClassNotFoundException: hello.Message

at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1365)

at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1315)

at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1068)

at java.lang.ClassLoader.loadClass(ClassLoader.java:356)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:186)

at org.hibernate.internal.util.ReflectHelper.classForName(ReflectHelper.java:192)

at org.hibernate.internal.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:228)

 31 more

Total time: 1 second

Pelo que entendi ele não encontrou a classe hello.Message e aí começa o problema. Mas ela está lá. Onde pode estar o erro?

Criado 1 de novembro de 2012
Ultima resposta 1 de nov. de 2012
Respostas 1
Participantes 1