Need to clarify and help. It is especially recommended to describe general concepts or the link where they are described.
So, on the sleep mode website, I read the following:
For use inside an application server, you should almost always configure Hibernate to receive connections from the application server. Javax.sql.Datasource is registered in JNDI. You will need to set at least one of the following properties:
And I have a few questions, because right now I'm really confused about all these things with DataSource, DataDriver, Tomcat and Hibernate in general.
- Does the data source configure and bind the SessionFactory to the JNDI is the same process?
- If not, why do we use a DataSource and why do we need to associate a SessionFactory with a JNDI (in general)?
- Did I understand correctly? If we configure the DataSource in the hibernate.cfg.xml file, do we need to configure it in {tomcat} /conf/server.xml or {tomcat} /conf/context.xml?
- What is
hibernate.jndi.url? Is it the same as hibernate.connection.url? - What is
hibernate.connection.datasource? I read in the docs that this is the “JNDI data source name”, so if I understood correctly, could it be any name? - I read from Hibernate docs that setting at least one of the properties
hibernate.connection.datasource, hibernate.jndi.url, hibernate.jndi.class, hibernate.connection.username, hibernate.connection.passwordmakes my application use javax.sql.Datasourceregistered in JNDI. So, is the following conf already configured to use a DataSource? - How to check what is
DataSourceused and configured normally?
hibernate.cfg.xml :
<?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.show_sql">true</property>
<property name="hibernate.use_sql_comments">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.generate_statistics">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.datasource">jdbc:mysql://localhost/easywordweb</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/easywordweb</property>
<property name="hibernate.connection.username">username</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.c3p0.max_size">140</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.acquire_increment">5</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.timeout">21600</property>
<property name="hibernate.c3p0.preferredTestQuery">SELECT 1;</property>
<property name="hibernate.c3p0.testConnectionOnCheckout">true</property>
<property name="hibernate.c3p0.testConnectionOnCheckin">true</property>
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.validate">true</property>
<property name="hibernate.c3p0.idle_test_period">21000</property>
<property name="hibernate.jdbc.batch_size">20</property>
<property name="hibernate.jdbc.fetch_size">20</property>
<property name="hibernate.jdbc.use_get_generated_keys">true</property>
<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>
<property name="hibernate.id.new_generator_mappings">false</property>
</session-factory>
</hibernate-configuration>
.