Hibernate - Ajuda com *.hbm.xml

9 respostas
gutotal

Prezados, boa tarde.

Pesquisei, analisei, reanalizei o meu codigo porém muito devido ao fato de eu não possuir muito conhecimento venho pedir o auxilio de vocês com o meu problema (enxer o saco…rsrsrs)…

Eu estou tentando desenvolver uma aplicação desktop utilizando o hibernate e após criar o *.hbm, *.cfg, DAO do SessionFactory, Tela e o controle eu simplesmente não consigo me conectar ao BD…

Pelo que pesquisei parece ser algum problema no meu Pessoa.hbm.xml, mas não consegui identificar qual o problema…

Segue abaixo codigo:

Aos que puderem me dar ao menos uma dica, eu agradeço antecipadamente…abs.

?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
	<class name="Pessoa.pessoa" table="pessoa">
		<id name="codpessoa" column="codpessoa">
			<generator class="increment"></generator></id>
		<property name="nome">nome</property>
		<property name="rua"/>rua</property>
		<property name="numero"/>numero</property>
		<property name="complemento"/></property>
		<property name="bairro"></property>
		<property name="telefone"></property>
		<property name="uf"></property>
		<property name="email"></property>
		<property name="cidade"></property>
		<property name="cep"></property>
		<joined-subclass name="Pessoa.pessoaFisica" table="pessoafisica">
			<key column="codpessoa"></key>
			<property name="cpf"></property>
			<property name="rg"></property>
			<property name="sexo"></property>
			<property name="dataNasc"></property>
		</joined-subclass>
		<joined-subclass name="Pessoa.pessoaJuridica" table="pessoajuridica">
			<key column="codpessoa"></key>
			<property name="cnpj"></property>
			<property name="inscEstadual"></property>
		</joined-subclass>
		<joined-subclass name="Pessoa.funcionario" table="funcionario">
			<key column="codpessoa"></key>
			<property name="matricula"></property>
			<property name="estadoCivil"></property>
			<property name="naturalidade"></property>
			<property name="nacionalidade"></property>
			<property name="funcao"></property>
			<property name="login"></property>
			<property name="senha"></property>
			<property name="dataAdmissao"></property>
		</joined-subclass>
	</class>

</hibernate-mapping>

PS: Caso o titulo ou algo mais esteja fora dos padrões estabelecidos pelo forum perdoem-me…é só informar que sendo necessário eu corrijo.

Abs

Carlos Guerra

9 Respostas

drsmachado

Qual o erro?

gutotal

O erro é este

Exception in thread "AWT-EventQueue-0" org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1494)
	at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
	at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
	at Controle.controlePessoaFisica.actionPerformed(controlePessoaFisica.java:53)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$000(Unknown Source)
	at java.awt.EventQueue$1.run(Unknown Source)
	at java.awt.EventQueue$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$2.run(Unknown Source)
	at java.awt.EventQueue$2.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: org.dom4j.DocumentException: Error on line 9 of document  : The element type "name" must be terminated by the matching end-tag "</name>". Nested exception: The element type "name" must be terminated by the matching end-tag "</name>".
	at org.dom4j.io.SAXReader.read(SAXReader.java:482)
	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1484)
	... 39 more

Obrigado

gutotal

Socorro!

drsmachado

Camarada, isso aqui está completamente errado: <property name="nome">nome</property> <property name="rua"/>rua</property> <property name="numero"/>numero</property> <property name="complemento"/></property> <property name="bairro"></property> <property name="telefone"></property>

Veja estes exemplos aqui http://www.allapplabs.com/hibernate/hibernate_comlete_example_hbm_files.htm

Lucas_Abbatepaolo

Amigo,

creio que seu problema seja no proprio arquivo de configuração do hibernate (hibernate.cfg.xml).
na linha 9 do documento. Pelo que esta no stack trace faltou vc fechar a tag name. Poste o arquivo de configuração se possivel.

Caused by: org.dom4j.DocumentException: Error on line 9 of document  : The element type "name" must be terminated by the matching end-tag "</name>". Nested exception: The element type "name" must be terminated by the matching end-tag "</name>".

flw…

gutotal
Lucas Abbatepaolo:
Amigo,

creio que seu problema seja no proprio arquivo de configuração do hibernate (hibernate.cfg.xml).
na linha 9 do documento. Pelo que esta no stack trace faltou vc fechar a tag name. Poste o arquivo de configuração se possivel.

Caused by: org.dom4j.DocumentException: Error on line 9 of document  : The element type "name" must be terminated by the matching end-tag "</name>". Nested exception: The element type "name" must be terminated by the matching end-tag "</name>".

flw...

Lucas,

Você acertou tinha um parametro maluco lá no meu cfg do tipo que não estava fechado. Depois que eu acertei isto agora o erro é outro.... :evil:
0 [AWT-EventQueue-0] INFO cfg.Environment  - Hibernate 3.2.5
15 [AWT-EventQueue-0] INFO cfg.Environment  - hibernate.properties not found
15 [AWT-EventQueue-0] INFO cfg.Environment  - Bytecode provider name : cglib
31 [AWT-EventQueue-0] INFO cfg.Environment  - using JDK 1.4 java.sql.Timestamp handling
156 [AWT-EventQueue-0] INFO cfg.Configuration  - configuring from resource: /hibernate.cfg.xml
156 [AWT-EventQueue-0] INFO cfg.Configuration  - Configuration resource: /hibernate.cfg.xml
312 [AWT-EventQueue-0] INFO cfg.Configuration  - Reading mappings from resource : Pessoa/Pessoa.hbm.xml
328 [AWT-EventQueue-0] ERROR util.XMLHelper  - Error parsing XML: XML InputStream(1) Content is not allowed in prolog.
IWAV0052E Invocation Target Exception creating visao.CadastroPFjava.lang.reflect.InvocationTargetException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.eclipse.ve.internal.java.vce.launcher.remotevm.JFCLauncher$1.run(JFCLauncher.java:59)
	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource Pessoa/Pessoa.hbm.xml
	at org.hibernate.cfg.Configuration.addResource(Configuration.java:569)
	at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
	at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
	at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
	at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
	at Controle.controleClientePF.<init>(controleClientePF.java:60)
	at visao.CadastroPF.<init>(CadastroPF.java:72)
	... 13 more
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream
	at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:508)
	at org.hibernate.cfg.Configuration.addResource(Configuration.java:566)
	... 21 more
Caused by: org.dom4j.DocumentException: Error on line 1 of document  : Content is not allowed in prolog. Nested exception: Content is not allowed in prolog.
	at org.dom4j.io.SAXReader.read(SAXReader.java:482)
	at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:499)
	... 22 more

Pelo que entendi do erro, é algo referente ao mapeamento do arquivo Pessoa.hbm.xml....estou correto?

O meus arquivos estão assim:

Pessoa.hbm.xml
?xml version="1.0"?>  
<!DOCTYPE hibernate-mapping PUBLIC  
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"  
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">  
<hibernate-mapping>  
    <class name="Pessoa.pessoa" table="pessoa">  
        <id name="idPessoa" column="codpessoa">  
            <generator class="increment"></generator></id>  
        <property name="nome"></property>  
        <property name="rua"/></property>  
        <property name="numero"/></property>  
        <property name="complemento"/></property>  
        <property name="bairro"></property>  
        <property name="telefone"></property>  
        <property name="uf"></property>  
        <property name="email"></property>  
        <property name="cidade"></property>  
        <property name="cep"></property>  
        <joined-subclass name="Pessoa.pessoaFisica" table="pessoafisica">  
            <key column="codpessoa"></key>  
            <property name="cpf"></property>  
            <property name="rg"></property>  
            <property name="sexo"></property>  
            <property name="dataNasc"></property>  
        </joined-subclass>  
        <joined-subclass name="Pessoa.pessoaJuridica" table="pessoajuridica">  
            <key column="codpessoa"></key>  
            <property name="cnpj"></property>  
            <property name="inscEstadual"></property>  
        </joined-subclass>  
        <joined-subclass name="Pessoa.funcionario" table="funcionario">  
            <key column="codpessoa"></key>  
            <property name="matricula"></property>  
            <property name="estadoCivil"></property>  
            <property name="naturalidade"></property>  
            <property name="nacionalidade"></property>  
            <property name="funcao"></property>  
            <property name="login"></property>  
            <property name="senha"></property>  
            <property name="dataAdmissao"></property>  
        </joined-subclass>  
    </class>  
  
</hibernate-mapping>
Hibernate.cfg.xml
<?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>
    <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
    <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
    <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/BGN</property>
    <property name="hibernate.connection.username">postgres</property>
    <property name="hibernate.connection.password">xxxxxx</property>
    <property name="hibernate.show_sql">true</property>
    <mapping resource="Pessoa/Pessoa.hbm.xml"/>
    
  </session-factory>
</hibernate-configuration>

Ainda não consegui identificar o que estaria errado neste mapeamento. A estrutura da aplicação é utilizando o mapeamento por subclasses, sendo as classes PessoaFisica e PessoJuridica, subclasses da classe Pessoa.

Lucas_Abbatepaolo

Não esta faltando um < no começo do arquivio de mapeamento da classe Pessoa?? ou foi falha no copy paste?rs

gutotal

Lucas VOCÊ É O CARA!!! :lol:

Valeu mesmo. Uma coisa que pode parecer ridicula porém, para quem não conhece identificar só perguntando a quem sabe muito!!!

Muito obrigado mesmo!

Abraço

Lucas_Abbatepaolo

Obrigado…

precisando post ai… faremos o maximo que pudermos para te ajudar…

Bons estudos…

Ps: não esqueça de colocar no titulo do post [RESOLVIDO], assim todos sabem que o problema foi solucionado…

Criado 15 de novembro de 2011
Ultima resposta 16 de nov. de 2011
Respostas 9
Participantes 3