Conforme combinado, os interessado em dar continuidade nos exercícios, estarei dispostos a auxiliar nas dúvidas.
Entrem em contato através do e-mail marconato10@gmail.com
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://server:port/database
hibernate.connection.username=user
hibernate.connection.password=pass
hibernate.hbm2ddl.auto=update
<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://server:port/database</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping class="br.com.Entidade1"/>
<mapping class="br.com.Entidade2"/>
<mapping class="br.com.Entidade3"/>
</session-factory>
</hibernate-configuration>
public class HibernateUtil {
private static SessionFactory factory;
private static String HIBERNATE_PROPERTIES_FILE_NAME = "hibernate.properties";
static{
Properties hibernateProperties = new Properties();
InputStream in;
try {
in = new FileInputStream(HibernateUtil.HIBERNATE_PROPERTIES_FILE_NAME);
hibernateProperties.load(in);
in.close();
factory = new AnnotationConfiguration().configure().setProperties(hibernateProperties).buildSessionFactory();
} catch (Exception ex) {
try {
factory = new AnnotationConfiguration().configure().buildSessionFactory();
} catch (Throwable e) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + e);
throw new ExceptionInInitializerError(ex);
}
}
}
/**
* Abre e retorna a Sessão Hibernate
* @return Session
*/
public static Session getSession() {
return factory.openSession();
}
}