TO TENTANDO APREDER COMO USAR O HIBERNATE NA UNHA, MAS TA FOGO
TA DANDO ESTE ERRO QUE SEGUE ABAIXO, TO USANDO ODBC COM ACCESS.
CLASSE PESSOA
public class Pessoa {
private String nome;
private String email;
private String telefone;
} // MAIS GET E SET....
PESSOA.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>
<class name="Pessoa">
<!-- Propriedades da classe -->
<property name="nome"/>
<property name="telefone"/>
<property name="email"/>
</class>
</hibernate-mapping>
HIBERNATE.CFG.HTML
<!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">
sun.jdbc.odbc.JdbcOdbcDriver
</property>
<property name="hibernate.connection.url">
jdbc:ODBC:hibernate?autoReconnect=true
</property>
<!-- Configuracoes 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>
<!-- Configuracoes 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="Pessoa.hbm.xml"/>
</session-factory>
</hibernate-configuration>
CLASSE TESTE
[code]import org.hibernate.Session;
import org.hibernate.Transaction;
public class Teste {
public static void main(String[] args) {
Session sessao = HibernateUtility.getSession(); //Abrindo uma sessão
Transaction transaction = sessao.beginTransaction(); //Iniciando uma transação
Pessoa pessoa = new Pessoa(); //Instanciando um objeto transiente
pessoa.setNome("Adalberto Silva"); //Preenchendo as propriedades do objeto
pessoa.setEmail("asrodrigues@tce.sp.gov.br");
pessoa.setTelefone("4544-4545");
sessao.save(pessoa);
transaction.commit(); //Finalizando a transação
sessao.close(); //Fechando a sessão
}
}
[/code]
CLASSE HibernateUtility
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();
}
}
ERRO ERRO ERRO
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
org.hibernate.MappingException: Could not read mappings from resource: Pessoa.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:523)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1511)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1479)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1458)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1432)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1352)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1338)
at Principal.HibernateUtility.<clinit>(HibernateUtility.java:11)
at Principal.Teste.main(Teste.java:8)
Caused by: org.hibernate.MappingException: invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:463)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:520)
... 8 more
Caused by: org.xml.sax.SAXParseException: The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:460)
... 9 more
java.lang.NullPointerException
at Principal.HibernateUtility.getSession(HibernateUtility.java:19)
at Principal.Teste.main(Teste.java:8)
Exception in thread "main"