<?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:3306/tremdados</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">admin</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="current_session_context_class">thread</property>
<mapping resource="Persistencia/Usuario.hbm.xml"/>
<mapping resource="Persistencia/Cliente.hbm.xml"/>
</session-factory>
</hibernate-configuration>
<property name="current_session_context_class">thread</property>
package Persistencia;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.SessionFactory;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new AnnotationConfiguration()
.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect")
.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver")
.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/tremdados")
.setProperty("hibernate.connection.username", "root")
.setProperty("hibernate.connection.password", "admin")
.setProperty("current_session_context_class", "thread")
.setProperty("hibernate.show_sql", "true")
.setProperty("hibernate.format_sql", "true")
//---------------- c3p0 inicio -------------------------------------------------------------------
// .setProperty("hibernate.c3p0.acquire_increment", "1")
// .setProperty("hibernate.c3p0.idle_test_period", "100")
// .setProperty("hibernate.c3p0.max_size", "10")
// .setProperty("hibernate.c3p0.max_statements", "0")
// .setProperty("hibernate.c3p0.min_size", "5")
// .setProperty("hibernate.c3p0.timeout", "100")
//---------------- c3p0 fim-------------------------------------------------------------------
.addResource("Persistencia/Cliente.hbm.xml")
.addResource("Persistencia/Usuario.hbm.xml").buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
.setProperty("current_session_context_class", "thread")
Aguem poderia me ajudar com as seguintes questões:
1) Onde estou errando ?
2) Como fazer para receber via argumento o usuário e a senha ?
3) Como usar o c3p0, porque se descomentar as linha c3p0 dá essa exceção:
Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: com/mchange/v2/c3p0/DataSources
Exception in thread "main" java.lang.ExceptionInInitializerError
Grato.