1
I got the following hibernate.cfg.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<!-- Configuração para a instância do SessionFactory -->
<session-factory>
<!-- Propriedades para o Hibernate -->
<property name="hibernate.dialect">
org.hibernate.dialect.MySQL5InnoDBDialect
</property>
<property name="hibernate.show_sql">
true
</property>
<property name="hibernate.connection.provider_class">
com.zaxxer.hikari.hibernate.HikariConnectionProvider
</property>
<property name="hibernate.current_session_context_class">
thread
</property>
<property name="hibernate.generator_mappings">
true
</property>
<!-- Propriedades para o Pool de Conexões HirakiCP -->
<property name="hibernate.hikari.dataSourceClassName">
com.mysql.jdbc.jdbc2.optional.MysqlDataSource
</property>
<property name="hibernate.hikari.dataSource.url">
jdbc:mysql://localhost:3306/teste-database1?createDatabaseIfNotExist=true
</property>
<property name="hibernate.hikari.dataSource.user">
root
</property>
<property name="hibernate.hikari.dataSource.password">
admin123
</property>
<property name="hibernate.hikari.maximumPoolSize">
10
</property>
<property name="hibernate.hikari.idleTimeout">
30000
</property>
<property name="hibernate.hikari.dataSource.cachePrepStmts">
true
</property>
<property name="hibernate.hikari.dataSource.prepStmtCacheSize">
250
</property>
<property name="hibernate.hikari.dataSource.prepStmtCacheSqlLimit">
2048
</property>
<property name="hibernate.hikari.dataSource.useServerPrepStmts">
true
</property>
<property name="hibernate.hikari.dataSource.useLocalSessionState">
true
</property>
<property name="hibernate.hikari.dataSource.useLocalTransactionState">
true
</property>
<property name="hibernate.hikari.dataSource.maintainTimeStats">
false
</property>
<property name="hibernate.hikari.dataSource.useUnbufferedInput">
false
</property>
<!-- Mapeamento de classes -->
<!-- <mapping package="org.sgct.model" /> -->
<mapping class="org.teste.model.Usuario" />
<mapping class="org.teste.model.Contato" />
<mapping class="org.teste.model.Endereco" />
</session-factory>
</hibernate-configuration>
Doubts
1 - In the Spring configuration file (applicationContext.xml for example) instead of having to enter each property in this file, you can take advantage of file settings hibernate.cfg.xml
using the following code excerpt:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="configLocation" value="classpath*:hibernate.cfg.xml" />
</bean>
But I don’t know what properties he takes advantage of hibernate.cfg.xml
when using this code snippet. What I want to understand is which properties it takes advantage of (like maybe class mapping snippets) in addition to the basic properties (dialect, providade_class, etc.) so that I can complement the snippet with properties it doesn’t use.
2 - When configured the connection pool (in my case I am using Hikaricp) there is a similar way to take advantage of the configuration of another file as in the configuration snippet of Hibernate that I presented in the previous question?
3 - I intend to use JNDI in an xml file (in the case of Tomcat it was the file context.xml
) because in addition to Hibernate I will use Spring Security, but how I use Glassfish I don’t know if this configuration that is in the Hirakicp project repository will work the same way in Glassfish because it is for Tomcat. I also don’t know if all or part of the connection pool configuration will go to the JNDI configuration file.
4 - There is also the case of referencing the connection in the configuration section of Hibernate as in my version of hibernate.cfg.xml
that I put up I use the property hibernate.connection.provider_class
but in this article the property is used dataSource
. What is the difference between the use of one or the other? When using JNDI is used which of these?
A recommendation, even knowing that the questions are related, as far as possible try to break your doubts into multiple questions (this not only helps the site catalog, but increases your chances as it may be that a user is able to answer one but not all questions).
– Anthony Accioly
I get it. Thank you Anthony.
– klaytonbrito
No problem, I wrote the answer while you were editing, I didn’t realize you had subdivided. If you want to do rollback no problem, the advice was more to help you get answers (if you want to leave subdivided I "refatoro" here too).
– Anthony Accioly
No need more, but thanks. I was subdividing the questions, but as you put an answer I came back the way it was to not complicate. But the next few questions I know how to do.
– klaytonbrito