estou tentando executar um simples exemplo no hibernate e não consigo, é um erro atrás do outro.
estou usando eclipse europa
hibernate:3
os arquivos estão configurados em suas devidas pastas, conforme milhoes de arquivos que li na net.
se alguem puder me ajudar eu agradeço.
meu erro: org.hibernate.InvalidMappingException: Could not parse mapping document from resource Aluno.hbm.xml
erro detalhado:
INFO Environment:514 - Hibernate 3.2.6
org.hibernate.InvalidMappingException: Could not parse mapping document from resource Aluno.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:575)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1593)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1561)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1540)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1514)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1434)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1420)
at bean.TesteMain.(TesteMain.java:17)
Caused by: org.hibernate.MappingException: class Aluno not found while looking for property: id
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:74)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:279)
at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:401)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:334)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:273)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:144)
at org.hibernate.cfg.Configuration.add(Configuration.java:675)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:510)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:572)
… 7 more
Caused by: java.lang.ClassNotFoundException: Aluno
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:70)
… 15 more
java.lang.NullPointerException
at bean.TesteMain.getSession(TesteMain.java:28)
at bean.TesteMain.adiciona(TesteMain.java:34)
at bean.TesteMain.main(TesteMain.java:52)
22:12:51,187 INFO Environment:547 - hibernate.properties not found
22:12:51,187 INFO Environment:681 - Bytecode provider name : cglib
22:12:51,187 INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
22:12:51,281 INFO Configuration:1432 - configuring from resource: /hibernate.cfg.xml
22:12:51,281 INFO Configuration:1409 - Configuration resource: /hibernate.cfg.xml
22:12:51,546 DEBUG DTDEntityResolver:38 - trying to resolve system-id [<a href="http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd</a>]
22:12:51,562 DEBUG DTDEntityResolver:40 - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
22:12:51,562 DEBUG DTDEntityResolver:50 - located [<a href="http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd</a>] in classpath
22:12:51,609 DEBUG Configuration:1393 - hibernate.dialect=org.hibernate.dialect.MySQLDialect
22:12:51,609 DEBUG Configuration:1393 - hibernate.connection.driver_class=com.mysql.jdbc.Driver
22:12:51,609 DEBUG Configuration:1393 - hibernate.connection.url=jdbc:mysql://localhost:3306/testehibernate
22:12:51,609 DEBUG Configuration:1393 - hibernate.connection.username=root
22:12:51,609 DEBUG Configuration:1393 - hibernate.connection.password=
22:12:51,609 DEBUG Configuration:1393 - hibernate.c3p0.max_size=10
22:12:51,609 DEBUG Configuration:1393 - hibernate.c3p0.min_size=2
22:12:51,609 DEBUG Configuration:1393 - hibernate.c3p0.timeout=5000
22:12:51,609 DEBUG Configuration:1393 - hibernate.c3p0.max_statements=10
22:12:51,609 DEBUG Configuration:1393 - hibernate.c3p0.idle_test_period=3000
22:12:51,609 DEBUG Configuration:1393 - hibernate.c3p0.acquire_increment=2
22:12:51,609 DEBUG Configuration:1393 - show_sql=true
22:12:51,609 DEBUG Configuration:1393 - use_outer_join=true
22:12:51,609 DEBUG Configuration:1393 - hibernate.generate_statistics=true
22:12:51,609 DEBUG Configuration:1393 - hibernate.use_sql_comments=true
22:12:51,609 DEBUG Configuration:1592 - null<-org.dom4j.tree.DefaultAttribute@cdfc9c [Attribute: name resource value “Aluno.hbm.xml”]
22:12:51,609 INFO Configuration:559 - Reading mappings from resource : Aluno.hbm.xml
22:12:51,625 DEBUG DTDEntityResolver:38 - trying to resolve system-id [<a href="http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd</a>]
22:12:51,625 DEBUG DTDEntityResolver:40 - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
22:12:51,625 DEBUG DTDEntityResolver:50 - located [<a href="http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd</a>] in classpath
22:12:51,734 INFO HbmBinder:300 - Mapping class: Aluno -> Aluno
classe basica
package bean;
public class Aluno {
private int id;
private String nome;
private String cpf;
public Aluno(){
}
public Aluno(String nome, String cpf) {
super();
this.nome = nome;
this.cpf = cpf;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getCpf() {
return cpf;
}
public void setCpf(String cpf) {
this.cpf = cpf;
}
}
Aluno.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<class name="Aluno">
<id name="id" column="idAluno" >
<generator class="increment" />
</id>
<property name="nome" />
<property name="cpf" />
</class>
hibernate.cfg.xml
<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:3306/testehibernate
</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></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="use_outer_join">true</property>
<property name="hibernate.generate_statistics">true</property>
<property name="hibernate.use_sql_comments">true</property>
<mapping class="Aluno" resource="Aluno.hbm.xml"/>
<!-- mapping resource= bean/Aluno.hbm.xml -->
<!-- mapping class= Aluno file=bean/Aluno.hbm.xml-->
<!--ja tentei os dois acima e nada-->
</session-factory>
log4j.properties
direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
direct messages to file hibernate.log
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=hibernate.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
set log levels - for more verbose logging change ‘info’ to ‘debug’
log4j.rootLogger=warn, stdout, file
#log4j.logger.org.hibernate=info
log4j.logger.org.hibernate=debug
log just the SQL
#log4j.logger.org.hibernate.SQL=debug
log JDBC bind parameters
log4j.logger.org.hibernate.type=info
#log4j.logger.org.hibernate.type=debug
log schema export/update
log4j.logger.org.hibernate.tool.hbm2ddl=debug
log HQL parse trees
#log4j.logger.org.hibernate.hql=debug
log cache activity
#log4j.logger.org.hibernate.cache=debug
log JDBC resource acquisition
#log4j.logger.org.hibernate.jdbc=debug
enable the following line if you want to track down connection
leakages when using DriverManagerConnectionProvider
#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace
classe main
package bean;
import javax.transaction.Transaction;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class TesteMain {
private static SessionFactory factory;
static {
// Bloco estático que inicializa o Hibernate
try {
factory = new Configuration().configure().buildSessionFactory();
} catch (Exception e) {
e.printStackTrace();
factory = null;
}
}
public static Session getSession() {
return factory.openSession();
}
public static void adiciona(Aluno aluno) throws Exception {
Session session = ((SessionFactory) getSession()).getCurrentSession();
Transaction transaction = (Transaction) session.beginTransaction();
session.save(aluno);
session.flush();
transaction.commit();
session.close();
//System.out.println("Nome:" + aluno.getNome());
}
public static void main(String[] args) {
Aluno aluno = new Aluno();
aluno.setNome("david");
aluno.setCpf("123");
try {
adiciona(aluno);
} catch (Exception e) {
e.printStackTrace();
}
}
}