I have 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>
Questions
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 settings of the hibernate.cfg.xml
file using the following code snippet:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="configLocation" value="classpath*:hibernate.cfg.xml" />
</bean>
But I do not know what properties it takes advantage of from the hibernate.cfg.xml
file when using this code snippet. What I want to understand is what properties it takes (like perhaps class mapping snippets) in addition to the basic properties (dialect, class_provity, etc.) so I can supplement the snippet with properties it does not use.
2 - When configuring the connection pool (in my case I'm using HikariCP) is there similar way to take advantage of the configuration of another file as in the configuration section of hibernate that I presented in the previous question?
3 - I want to use JNDI in an xml file (Tomcat was the context.xml
file) because in addition to Hibernate I will use Spring Security, but since I use Glassfish I do not know if This configuration that is in the HirakiCP project repository will work the same in Glassfish for the fact to be for Tomcat. I also do not 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 because as in my version of hibernate.cfg.xml
that I put above I use the hibernate.connection.provider_class
property but in this article the dataSource
property is used. What is the difference between using one or the other? When JNDI is used which one of these?