Erro Hibernate [RESOLVIDO]

13 respostas
K
Sou iniciante em java, estava tentando usar o hibernate para persistir os dados está aparecendo o seguinte erro.
run:
94 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
110 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.6.0.Final
110 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
110 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
110 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
172 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: hibernate/hibernate.cfg.xml
172 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: hibernate/hibernate.cfg.xml
500 [main] WARN org.hibernate.util.DTDEntityResolver - recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
org.hibernate.HibernateException: Could not parse configuration: hibernate/hibernate.cfg.xml
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2216)
        at org.hibernate.cfg.Configuration.configure(Configuration.java:2128)
        at model.Teste.main(Teste.java:23)
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:2208)
        ... 2 more
meu arquivo de configuracao é
<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : hibernate.cfg.xml
    Created on : 27 de Janeiro de 2011, 08:05
    Author     : Administrador
    Description:
        Purpose of the document follows.
-->

<!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>
        <property name="hibernate.connection.driver_class">
            oracle.jdbc.driver.OracleDriver
        </property>
        <property name="hibernate.connection.url">
            jdbc:oracle:thin:@127.0.0.1:1521:xe
        </property>
        <property name="hibernate.connection.username">
            tecnicos
        </property>
        <property name="hibernate.connection.password">
            tecnicos
        </property>
        <property name="hibernate.connection.dialect">
            org.hibernate.dialect.Oracle10gDialect
        </property>
        <mapping resource="hibernate/empresa.hbm.xml"/>
    </session-factory>
</hibernate-configuration>
e o meu de mapeamento é
<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : empresa.hbm.xml
    Created on : 27 de Janeiro de 2011, 08:37
    Author     : Administrador
    Description:
        Purpose of the document follows.
-->

<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">



<hibernate-mapping>
    <class name="model.Empresa">
        <id name="emp_id"/>
        <property name="emp_fili_codi"/>
        <property name="emp_nome"/>
        <property name="emp_email"/>
    </class>
</hibernate-mapping>

por favor me ajudem.

13 Respostas

J

Aparentemente seu problema esta no Hibernate Util…
posta ele pra nos verificarmos!

P

esse banco esta acessível???

K

Sim. É um Oracle 10G Express Edition que está instalado na minha maquina local.

P
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:@127.0.0.1:1521:xe", "tecnicos","tecnicos");

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

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

se vc usar essa classe o q acontece???

o serviço do banco esta iniciado? o listener tb??

att,

K

Ao executar a classe ConnectionFactory
conecta normalmente.

run:
Conectou!
CONSTRUÍDO COM SUCESSO (tempo total: 5 segundos)

P

vê se ajuda:

http://www.guj.com.br/java/117522-erro-hibernate-resolvido
http://www.coderanch.com/t/216716/ORM/java/Could-not-parse-hibernate-cfg
https://forum.hibernate.org/viewtopic.php?p=2372397

e posta ai o seu Teste.java

att,

K
ta ai
public class Teste {
    public static void main(String[] args){
        try{
            SessionFactory factory = new Configuration().configure().buildSessionFactory();
            Session session = factory.openSession();
            Transaction tx = session.beginTransaction();
            Empresa p = new Empresa();
            p.setEmp_id(1);
            p.setEmp_fili_codi(2);
            p.setEmp_nome("kldklaskdlas");
            p.setEmp_email("kd@dajdajksd");
            
            session.save(p);
            tx.commit();
            session.close();

        }catch(HibernateException e1){
            e1.printStackTrace();
        }

    }
}
K
Eu mudei meu hibernate.cfg.xml para
<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : hibernate.cfg.xml
    Created on : 27 de Janeiro de 2011, 08:05
    Author     : Administrador
    Description:
        Purpose of the document follows.
-->

<!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>
        <property name="hibernate.connection.driver_class">
            oracle.jdbc.driver.OracleDriver
        </property>
        <property name="hibernate.connection.url">
            jdbc:oracle:thin:@127.0.0.1:1521:xe
        </property>
        <property name="hibernate.connection.username">tecnicos</property>
        <property name="hibernate.connection.password">tecnicos</property>
        <property name="hibernate.connection.dialect">
            org.hibernate.dialect.Oracle10gDialect
        </property>
        <mapping resource="hibernate/empresa.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

e apresentou os seguintes erros.

run:
94 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
109 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.6.0.Final
109 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
125 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
125 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
187 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
187 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
266 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : hibernate/empresa.hbm.xml
297 [main] WARN org.hibernate.util.DTDEntityResolver - recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
328 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
Exception in thread "main" java.lang.NoClassDefFoundError: javax/persistence/EntityListeners
at org.hibernate.cfg.annotations.reflection.JPAMetadataProvider.getDefaults(JPAMetadataProvider.java:96)
at org.hibernate.annotations.common.reflection.java.JavaReflectionManager.getDefaults(JavaReflectionManager.java:226)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1355)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1826)
at model.Teste.main(Teste.java:22)
Caused by: java.lang.ClassNotFoundException: javax.persistence.EntityListeners
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 5 more
Java Result: 1
CONSTRUÍDO COM SUCESSO (tempo total: 0 segundos)

K

A versao do hibernate que eu estou usando é a hibernate-distribution-3.6.0.Final-dist

P

para essa sua 2° versão do cfg:

http://www.coderanch.com/t/513512/ORM/java/Error-java-lang-NoClassDefFoundError-javax
https://forum.hibernate.org/viewtopic.php?f=1&t=1007502
http://technicalrecyclebin.wordpress.com/2010/11/29/exception-in-thread-main-java-lang-noclassdeffounderror-javaxpersistenceentitylisteners/

att,

K

Obrigado

Estava faltando o jar hibernate-jpa-2.0-api-1.0.0.Final.jar

P

show de bola!

se estiver td ok não esqueça do [Resolvido]

att,

L

Vlw, era o mesmo problema que estava enfrentando, faltava o Jpa

Criado 27 de janeiro de 2011
Ultima resposta 28 de dez. de 2012
Respostas 13
Participantes 4