Erro de mapeamento da classe no hibernate

Erro de mapeamento da classe no hibernate.
Eu tenho a classe Contato na package com.livro.capitulo3.crudxml

e eu mapiei assim:

No xml Contato.hbm.xml :

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-mapping package="com.livro.capitulo3.crudxml">
	<class name="Contato" table="contato">
		<id name="codigo" column="codigo">
		<generator class="increment"/>
		</id>
		<propety name="nome"/>
		<propety name="telefone"/>
		<propety name="email"/>
		<propety name="dataCadastro" type="date" column="dt_cad"/>
		<propety name="observacao" type="string" column="obs"/>
	</class>
</hibernate-mapping>

e na configurações do hibernate:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    
    <!--  Configuração da conexão com o banco Oracle e dialeto -->
    <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
    <property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
    <property name="connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
    <property name="connection.username">tathi</property>
    <property name="connection.password">tathi</property>
    <property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
    <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
    <property name="current_session_context_class">thread</property>
    <property name="hibernate.show_sql">false</property>
   
    <!-- Usando as configurações do C3PO para o pool de conexões -->
    <property name="c3po.min_size">5</property>
    <property name="c3po.max_size">20</property>
    <property name="c3po.timeout">300</property>
    <property name="c3po.max_statements">50</property>
    <property name="c3po.idle_test_period">3000</property>
    
    <!--  Configurações de debug  -->
    <property name="show_sql">true</property>
    <property name="format_sql">true</property>
    <property name="generate_statistics">true</property>
    <property name="use_sql_comments">true</property>
   
    
    <!--  Mapeando classes -->
    <mapping resource="com/livro/capitulo3/crudxml/Contato.hbm.xml"/>
    
  </session-factory>
</hibernate-configuration>

Só que tah dando falha quando ele tenta mapear a classe contato.
Alguém sabe o motivo?
Obrigada

Qual a mensagem de erro?

Could not parse mapping document from resource com/livro/capitulo3/crudxml/Contato.hbm.xml

Isso significa que ele não está lendo o arquivo Contato.hbm.xml, ou por não tê-lo encontrado, ou por ter encontrado alguma marcação xml incorreta ou inexistente.

Tem certeza que o hibernate.cfg.xml encontra o arquivo Contato.hbm.xml? (quando pressiona CTRL e coloca o cursor do mouse na linha , exatamente sobre o endereço do arquivo, ele se torna um link? Consegue abri-lo?)

Oi! Obrigada por tentar me ajudar!!!
Então, forma um link sim e consigo abri-lo normalmente…
:frowning:

O que poso fazer, além de sentar e chorar???
rsrs

eu mudei o Contato.hbm.xml para:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-mapping>
	<class name="com.livro.capitulo3.crudxml.Contato" table="contato">
		<id name="codigo" column="codigo">
		<generator class="increment"/>
		</id>
		<propety name="nome"/>
		<propety name="telefone"/>
		<propety name="email"/>
		<propety name="dataCadastro" type="date" column="dt_cad"/>
		<propety name="observacao" type="string" column=""/>
	</class>
</hibernate-mapping>

e eu consigo clicar com o Ctrl na classe mapeada e consigo abri-la tb

A única cois que me chama atenção é que as propriedades nome, telefone e email não definem o atributo column…
Tirando isso, me parece certo.

e se eu copiar todo o erro? Ajuda??


SLF4J: The requested version 1.6 by your slf4j binding is not compatible with [1.5.5, 1.5.6, 1.5.7, 1.5.8]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
30 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.5.2-Final
30 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
35 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
40 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
190 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: hibernate.cfg.xml
190 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: hibernate.cfg.xml
305 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : com/livro/capitulo3/crudxml/Contato.hbm.xml
349 [main] ERROR org.hibernate.util.XMLHelper - Error parsing XML: XML InputStream(5) Document root element "hibernate-mapping", must match DOCTYPE root "hibernate-configuration".
349 [main] ERROR org.hibernate.util.XMLHelper - Error parsing XML: XML InputStream(5) Element type "hibernate-mapping" must be declared.
350 [main] ERROR org.hibernate.util.XMLHelper - Error parsing XML: XML InputStream(6) Element type "class" must be declared.
350 [main] ERROR org.hibernate.util.XMLHelper - Error parsing XML: XML InputStream(7) Element type "id" must be declared.
350 [main] ERROR org.hibernate.util.XMLHelper - Error parsing XML: XML InputStream(8) Element type "generator" must be declared.
351 [main] ERROR org.hibernate.util.XMLHelper - Error parsing XML: XML InputStream(10) Element type "propety" must be declared.
351 [main] ERROR org.hibernate.util.XMLHelper - Error parsing XML: XML InputStream(11) Element type "propety" must be declared.
351 [main] ERROR org.hibernate.util.XMLHelper - Error parsing XML: XML InputStream(12) Element type "propety" must be declared.
352 [main] ERROR org.hibernate.util.XMLHelper - Error parsing XML: XML InputStream(13) Element type "propety" must be declared.
352 [main] ERROR org.hibernate.util.XMLHelper - Error parsing XML: XML InputStream(14) Element type "propety" must be declared.
Exception in thread "main" Criação inicial do objeto SessionFactory falou. Erro: org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/livro/capitulo3/crudxml/Contato.hbm.xml
java.lang.ExceptionInInitializerErrorErro ao fechar a operação de inserção. Erro: null

	at com.livro.capitulo3.conexao.HibernateUtil.buildSessionFactory(HibernateUtil.java:17)
	at com.livro.capitulo3.conexao.HibernateUtil.<clinit>(HibernateUtil.java:8)
	at com.livro.capitulo3.crudxml.ContatoCrudXML.salvar(ContatoCrudXML.java:16)
	at com.livro.capitulo3.crudxml.ContatoCrudXML.main(ContatoCrudXML.java:134)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/livro/capitulo3/crudxml/Contato.hbm.xml
	at org.hibernate.cfg.Configuration.addResource(Configuration.java:671)
	at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1679)
	at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1647)
	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1626)
	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1600)
	at org.hibernate.cfg.Configuration.configure(Configuration.java:1520)
	at com.livro.capitulo3.conexao.HibernateUtil.buildSessionFactory(HibernateUtil.java:13)
	... 3 more
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from invalid mapping
	at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:604)
	at org.hibernate.cfg.Configuration.addResource(Configuration.java:668)
	... 9 more
Caused by: org.xml.sax.SAXParseException: Document root element "hibernate-mapping", must match DOCTYPE root "hibernate-configuration".
	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.rootElementSpecified(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
	at org.dom4j.io.SAXReader.read(SAXReader.java:465)
	at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:601)
	... 10 more

Já tive problemas parecidos.

Troque o campo

<?xml version='1.0' encoding='UTF-8'?>  
<!DOCTYPE hibernate-configuration PUBLIC  
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"  
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">  

Por

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

que se refere ao mapeamento de classes e não à configuração

eu troquei e a minha tag class ficou com erro : The content of element type “class” must match “(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|
composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|
dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array),((join,subclass*)|joined-
subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,fetch-profile*,resultset*,(query|sql-
query)*)”.

o mapeamento ficou:

<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE hibernate-mapping PUBLIC  
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"  
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">  
<hibernate-mapping package="com.livro.capitulo3.crudxml">  
    <class name="Contato" table="contato">  
        <id name="codigo" column="codigo">  
        <generator class="increment"/>  
        </id>  
        <propety name="nome"/>  
        <propety name="telefone"/>  
        <propety name="email"/>  
        <propety name="dataCadastro" type="date" column="dt_cad"/>  
        <propety name="observacao" type="string" column="obs"/>  
    </class>  
</hibernate-mapping>  

gente!!! Por favor me ajudem!!!
o que há de errado com isso::

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC  
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"  
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">  
<hibernate-mapping>  
    <class name="com.livro.capitulo3.crudxml.Contato" table="contato">  
        <id name="codigo" column="codigo">  
        <generator class="increment"/>  
        </id>  
        <propety name="nome" type="string" column="nome"/>  
        <propety name="telefone" type="string" column="telefone"/>  
        <propety name="email" type="string" column="email"/>  
        <propety name="dataCadastro" type="date" column="dt_cad"/>  
        <propety name="observacao" type="string" column="obs"/>  
    </class>  
</hibernate-mapping> 

e no cfg:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    
    <!--  Configuração da conexão com o banco Oracle e dialeto -->
    <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
    <property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
    <property name="connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
    <property name="connection.username">tathi</property>
    <property name="connection.password">tathi</property>
    <property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
    <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
    <property name="current_session_context_class">thread</property>
    <property name="hibernate.show_sql">false</property>
   
    <!-- Usando as configurações do C3PO para o pool de conexões -->
    <property name="c3po.min_size">5</property>
    <property name="c3po.max_size">20</property>
    <property name="c3po.timeout">300</property>
    <property name="c3po.max_statements">50</property>
    <property name="c3po.idle_test_period">3000</property>
    
    <!--  Configurações de debug  -->
    <property name="show_sql">true</property>
    <property name="format_sql">true</property>
    <property name="generate_statistics">true</property>
    <property name="use_sql_comments">true</property>
   
    
    <!--  Mapeando classes -->
    <mapping resource="com/livro/capitulo3/crudxml/Contato.hbm.xml"/> 
    
  </session-factory>
</hibernate-configuration>

Da a mensagem de erro: Could not parse mapping document from resource com/livro/capitulo3/crudxml/Contato.hbm.xml
Mas eu não consigo encontrar o que eu fiz de errado…

to com o mesmo erro…vc conseguiu resolver??

Já esperimento usar anotation para mapeamento ?

Consegui resolver!
Por algum motivo, o arquivo Contato.hbm.xml não conseguia fazer o mapeamento(apesar de estar identico ao do exercicio do livro). Exclui esse arquivo e peguei um q tava prestando de outra aplicação. Aí, foi só copiar o conteudo do arquivo antigo, reiniciar o Eclipse, e…voilá.

Obrigado.

1 curtida