Comecei a estudar o hibernate e fui acompanhando um tutorial q peguei na web. Ele diz que um arquivo(Curso.hbm.xml) não foi encontrado. Abaixo meus arquivos, todos.
Curso.hbm.xml
<?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.persistencia">
<class name="Curso">
<id name="id">
<generator class="increment"/>
</id>
<property name="descricao"></property>
<property name="nome"></property>
</class>
</hibernate-mapping>
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.MySQLDialect
</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/hibernate?autoReconnect=true</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">simbad</property>
<!-- Condiguração do c3p0 -->
<property name="hibernate.c3p0.max_size">10</property>
<property name="hibernate.c3p0.min_size">2</property>
<property name="hibernate.c3p0.timeout">5000</property>
<property name="hibernate.c3p0.max_statements">10</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<!-- Configurações de debug -->
<property name="show_sql">true</property>
<property name="hibernate.generate_statistics">true</property>
<property name="hibernate.use_sql_comments">true</property>
<mapping resource="Curso.hbm.xml"/>
<mapping resource="Disciplina.hbm.xml"/>
<mapping resource="Turma.hbm.xml"/>
<mapping resource="Pessoa.hbm.xml"/>
<mapping resource="Aluno.hbm.xml"/>
<mapping resource="Professor.hbm.xml"/>
<mapping resource="Endereco.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Meu UtilityHibernate
[code]package com.DAO;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtility {
private static SessionFactory factory;
static {
try {
factory = new Configuration().configure().buildSessionFactory();
} catch (Exception e) {
e.printStackTrace();
factory = null;
}
}
public static Session getSession() {
return factory.openSession();
}
}[/code]
Minha classe Curso
[code]package com.persistencia;
public class Curso {
private String nome;
private String descricao;
public void setNome(String nome){
this.nome = nome;
}
public String getNome(String nome){
return nome;
}
public void setDescricao(String descricao){
this.descricao = descricao;
}
public String getDescricao(String descricao){
return descricao;
}
}[/code]
E o erro que está dando
org.hibernate.MappingNotFoundException: resource: Curso.hbm.xml not found
at org.hibernate.cfg.Configuration.addResource(Configuration.java:769)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2314)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2280)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2260)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2213)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2128)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2107)
at com.persistencia.HibernateUtility.<clinit>(HibernateUtility.java:11)
at com.persistencia.Teste.main(Teste.java:10)
Exception in thread "main" java.lang.NullPointerException
at com.persistencia.HibernateUtility.getSession(HibernateUtility.java:18)
at com.persistencia.Teste.main(Teste.java:10)
Como eu estou aprendendo, alguns conceitos ainda não são claros. Espero ajuda de ocês.