Erro hibernate

8 respostas
R

Estou configurando hibernate mas esta com o seguinte erro:

  • Hibernate Commons Annotations 3.2.0.Final
  • Hibernate 3.6.7.Final
  • hibernate.properties not found
  • Bytecode provider name : javassist
  • using JDK 1.4 java.sql.Timestamp handling
  • configuring from resource: hibernate.cfg.xml
  • Configuration resource: hibernate.cfg.xml
  • recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
    Exception in thread “main” org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2246)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:2158)
    at com.green.dao.AssinaturaDAO.createSession(AssinaturaDAO.java:15)
    at com.green.dao.AssinaturaDAO.main(AssinaturaDAO.java:37)
    Caused by: org.dom4j.DocumentException: Connection timed out: connect Nested exception: Connection timed out: connect
    at org.dom4j.io.SAXReader.read(SAXReader.java:484)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2238)
    … 3 more

Meu hibernate.cfg.xml: (tem um alerta : The file cannot be validated as there was a connection problem.)

<?xml version="1.0" encoding="UTF-8"?> org.hibernate.dialect.Oracle10gDialect oracle.jdbc.driver.OracleDriver jdbc:oracle:thin:@192.168.1.36:1521:imgnh userAdmin teste imgnh false true false false org.hibernate.cache.NoCacheProvider thread

Meu hbm:

<?xml version="1.0" encoding="UTF-8"?>
<class name="com.green.entidade.Assinatura"
	table="ASSINATURA_GREEN" dynamic-insert="true"
	dynamic-update="true">

	<id name="codigoAssinatura" type="java.lang.Long" column="CD_ASSINATURA"
		unsaved-value="0">

		<generator class="sequence">
			<param name="sequence">ASSINATURA_GREEN_CD_ASSINATURA</param>
		</generator>
	</id>
	
	<property name="codigoDocumento" type="java.lang.String" not-null="true">
        <column name="CD_DOCUMENTO" />
    </property>
    
    <property name="assinaturaDocumentoString" type="java.lang.String" not-null="true">
        <column name="DS_ASSINATURA" />
    </property>
	
	<property name="dataAssinatura" type="java.util.Date"
		not-null="true">
		<column name="DT_ASSINATURA" />
	</property>

	<property name="nomeAssinatura" type="java.lang.String"
		not-null="true">
		<column name="NM_ASSINATURA" />
	</property>

	<property name="cpfAssinatura" type="java.lang.String"
		not-null="true">
		<column name="NR_CPF" />
	</property>

</class>

Executei esta classe, consegui conectar.

public class ConnectionFactory {

public static void main(String[] args) {

new ConnectionFactory().getConnection();

}
public void getConnection() {  

    try {  

        Class.forName("oracle.jdbc.driver.OracleDriver");  

        DriverManager.getConnection(  
                "jdbc:oracle:thin:@192.168.1.36:1521:imgnh", "userAdmin","teste");  

        System.out.println("Conectou!");  
    } catch (SQLException e) {  
        e.printStackTrace();  

    } catch (ClassNotFoundException e) {  
        e.printStackTrace();  
    }  
}

}

8 Respostas

Alys

Olá,

Acredito que você está enfrentando o problema descrito aqui: Hibernate Core Migration Guide : 3.6.

A dica está nesta linha do log que você postou:

recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!

Nota: ao postar códigos (fontes, xml, javascript, etc) envolva o conteúdo com a tag [code], facilita a visualização :wink:

romarcio

Pelo erro descrito parece ter algum erro arqui: &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.6.dtd"&gt; &lt;hibernate-configuration&gt;

Faça assim, va na referencia que vem junto com o pacote do hibernate que você baixou e copie de lá o trecho referente ao hibernate.cfg.xml

R

List of migration concerns as users migrate from 3.5 to 3.6
The namespaces for the Hibernate dtd files have changed.

Fui na referencia ajeitei meu arquivo de configuração e o hbm:

Agora exibiu o seguinte erro:

- Query cache: disabled
- Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
- Cache provider: org.hibernate.cache.NoCacheProvider
- Optimize cache for minimal puts: disabled
- Structured second-level cache entries: disabled
- Echoing all SQL to stdout
- Statistics: disabled
- Deleted entity synthetic identifier rollback: disabled
- Default entity-mode: pojo
- Named query checking : enabled
- Check Nullability in Core (should be disabled when Bean Validation is on): enabled
- building session factory
- Type registration [wrapper_characters_clob] overrides previous : org.hibernate.type.CharacterArrayClobType@1fddc31
- Type registration [materialized_blob] overrides previous : org.hibernate.type.MaterializedBlobType@1835282
- Type registration [blob] overrides previous : org.hibernate.type.BlobType@9df354
- Type registration [java.sql.Blob] overrides previous : org.hibernate.type.BlobType@9df354
- Type registration [clob] overrides previous : org.hibernate.type.ClobType@1d225a7
- Type registration [java.sql.Clob] overrides previous : org.hibernate.type.ClobType@1d225a7
- Type registration [characters_clob] overrides previous : org.hibernate.type.PrimitiveCharacterArrayClobType@1a62c31
- Type registration [wrapper_materialized_blob] overrides previous : org.hibernate.type.WrappedMaterializedBlobType@9f5011
- Type registration [materialized_clob] overrides previous : org.hibernate.type.MaterializedClobType@141b571
- Not binding factory to JNDI, no JNDI name configured
- Running hbm2ddl schema export
- exporting generated schema to database
- schema export complete
Exception in thread "main" org.hibernate.MappingException: Unknown entity: com.green.entidade.Assinatura
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:693)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1485)

Pesquisei na net, alterei o meu cfg, adicionei:

create-drop
true

Mas continua com este erro:
Exception in thread "main" org.hibernate.MappingException: Unknown entity: com.green.entidade.Assinatura

Meu cfg:

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

<hibernate-configuration>

    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin:@192.168.1.36:1521:imgnh</property>
        <property name="connection.username">green</property>
        <property name="connection.password">green</property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>
        <property name="hibernate.hbm2ddl.auto">create-drop</property>
        <property name="hibernate.jdbc.use_streams_for_binary">true</property>
    
    </session-factory>

</hibernate-configuration>

hbm:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
	"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping
	package="org.hibernate.test.cache.jbc.functional">

	<class name="Assinatura"
		table="ASSINATURA_GREEN" dynamic-insert="true"
		dynamic-update="true">

		<id name="codigoAssinatura" type="java.lang.Long" column="CD_ASSINATURA"
			unsaved-value="0">

			<generator class="sequence">
				<param name="sequence">ASSINATURA_GREEN_CD_ASSINATURA</param>
			</generator>
		</id>
		
		<property name="codigoDocumento" type="java.lang.String" not-null="true">
            <column name="CD_DOCUMENTO" />
        </property>
        
        <property name="assinaturaDocumentoString" type="java.lang.String" not-null="true">
            <column name="DS_ASSINATURA" />
        </property>
		
		<property name="dataAssinatura" type="java.util.Date"
			not-null="true">
			<column name="DT_ASSINATURA" />
		</property>

		<property name="nomeAssinatura" type="java.lang.String"
			not-null="true">
			<column name="NM_ASSINATURA" />
		</property>

		<property name="cpfAssinatura" type="java.lang.String"
			not-null="true">
			<column name="NR_CPF" />
		</property>

	</class>

</hibernate-mapping>
R

Sem querer tinha apgado o mapeamento do hbm :frowning:

<mapping resource="Assinatura.hbm.xml"> </mapping>

  • Hibernate Commons Annotations 3.2.0.Final
  • Hibernate 3.6.7.Final
  • hibernate.properties not found
  • Bytecode provider name : javassist
  • using JDK 1.4 java.sql.Timestamp handling
  • configuring from resource: /hibernate.cfg.xml
  • Configuration resource: /hibernate.cfg.xml
  • Error parsing XML: /hibernate.cfg.xml(30) The content of element type “mapping” must match “EMPTY”.
romarcio

Você precisa adicionar no arquivo hibernate.cfg.xml, todas as classes que possuem mapeamento.

&lt;mapping resource="org/hibernate/test/cache/jbc/functional/Assinatura.hbm.xml"/&gt;
R

adicionei:

Reading mappings from resource : org/hibernate/test/cache/jbc/functional/Assinatura.hbm.xml Exception in thread "main" org.hibernate.MappingNotFoundException: resource: org/hibernate/test/cache/jbc/functional/Assinatura.hbm.xml not found
O cfg e o hbm se encontram no pacote com/green/resources

Coloquei:

<mapping resource="com/green/resources/Assinatura.hbm.xml"/> 
<mapping resource="/Assinatura.hbm.xml"/>

O mesmo erro acontece ( org.hibernate.MappingNotFoundException)

romarcio

O arquivo Assinatura.hbm.xml e a classe Assinatura devem estar dentro do mesmo pacote.

R

Consegui :smiley:

Meu hbm se encontra em src/com/green/hbm
Minha entidade se encontra em src/com/green/entidade
Meu cfg se encontra no src

alterei meu hbm para

<hibernate-mapping package="com.green.entidade">

Meu cfg:

<mapping resource="com/green/hbm/Assinatura.hbm.xml"/>

Muito Obrigada!!!

Criado 19 de outubro de 2011
Ultima resposta 21 de out. de 2011
Respostas 8
Participantes 3