@Techies
Reframe the question with an appropriate title, based on the initial question at:
Hello.
Following the guidelines of another post, I have some questions, starting with the hibernate.cfg file:
<session-factory>
<!-- CONFIGURAÇÕES DO BANCO, TROCAR "NOMEDOBANCO" PARA O NOME DO SEU BANCO QUE JÁ FOI CRIADO -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/agenda</property>
<property name="connection.username">root</property>
<property name="connection.password">portal</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Dropa e Recria todas as tabelas, mudar para update ou validade após primeira execução -->
<property name="hbm2ddl.auto">create</property>
<!--AQUI VOCÊ MAPEIA SUA CLASSE AGENDA.-->
<mapping class="com.sistema.model.Agenda" />
</session-factory>
In this file the user who helped me talks about mapping the agenda class. The question is:
Even though I need to map my table to another class using Entity?
And about ddl commands that it speaks in comment lines, does that mean it's a dynamic process? Will you always drop and recreate? Sorry, I'm trying to understand. So much question.
HibernateUtil: (Put this class inside the useful package). The question is:
I create the package util? Where do I find the util? I also do not understand it, but once I apologize.
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
Configuration configuration = new Configuration();
configuration.configure();
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
And the user talks in test class to generate table:
public class GeraTabela {
public static void main(String[] args) {
HibernateUtil.getSessionFactory();
//TESTE
HibernateUtil.getSessionFactory().close();
}
}
If all goes well when you run this class your table will be created in the database.
I return to the question above: will it always be DDL?
A hug.