14 Ekim 2018 Pazar

hibernate.cfg.xml Dosyası - Connection Ayarları

Giriş
hibernate.properties dosyasındaki key değerler genellikle
hibernate.connection.driver=XXX şeklinde yazılıyor.

hibernate.cfg.xml dosyasında ise genellikle
connection.driver=XXX şeklinde yazılıyor yani hibernate kısmı atlanabilir.

connection.charset
Şöyle yaparız.
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="hibernate.cache.use_query_cache">false</property> 
<property name="show_sql">true</property>
<property name="hibernate.connection.CharSet">utf8</property>
<property name="hibernate.connection.characterEncoding">utf8</property>
<property name="hibernate.connection.useUnicode">true</property>
<property name="hibernate.connection.driver_class">
  com.mysql.jdbc.Driver
</property>
connection.driver_class
Şu değerler olabilir.
com.mysql.jdbc.Driver
org.postgresql.Driver
oracle.jdbc.driver.OracleDriver
Örnek
Şöyle yaparız
<hibernate-configuration>

  <session-factory>

    <!-- JDBC Database connection settings -->
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="connection.url">jdbc:mysql://localhost:3306/student</property>
    <property name="connection.username">hbstudent</property>
    <property name="connection.password">hbstudent</property>

    <!-- JDBC connection pool settings ... using built-in test pool -->
    <property name="connection.pool_size">1</property>

    <!-- Select our SQL dialect -->
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

    <!-- Echo the SQL to stdout -->
    <property name="show_sql">true</property>

    <!-- Set the current session context -->
    <property name="current_session_context_class">thread</property>

    </session-factory>

</hibernate-configuration>
connection.url
Örnek
jdbc:postgresql://a.b.c.d:5432/testdb
Örnek
Şöyle yaparız.
<property name="connection.url">jdbc:mysql://localhost:3306/reports?useSSL=true</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.username">***</property>
<property name="connection.password">***</property>
connection.username
Kullanıcı adı

hibernate.connection.password
Kullanıcı şifresi

hibernate.connection.pool_size
Şöyle yaparız.
<?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="dialect">org.hibernate.dialect.PostgreSQL9Dialect</property>
    <property name="connection.driver_class">org.postgresql.Driver</property>
    <property name="connection.url">jdbc:postgresql://localhost:5432/postgres</property>
    <property name="connection.username">pavel</property>
    <property name="connection.password">31228900</property>
    <property name="connection.pool_size">10</property>
    <property name="hbm2ddl.auto">create</property>

    <mapping resource="planetofUsers.cfg.xml"/>

  </session-factory>

</hibernate-configuration>
hibernate.connection.release_mode
Şu değerler olabilir. Varsayılan değer auto olduğu için xml'de belirtmeye gerek yok
auto
on_close
after_transaction
after_statement

Hiç yorum yok:

Yorum Gönder