Defining Dialect in Hibernate

MySQL Dialect
MySQL Dialect

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>  
    <session-factory>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/hibernate</property>
        <property name="connection.username">root</property>
        <property name="connection.password">pass</property>
        
        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.MySQLDialect</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>

        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">update</property>
        
        <!-- Name of the Annotated Entity class -->
        <mapping class="com.mugil.dto.UserDetails"/>
    </session-factory>
</hibernate-configuration>

If hbm2ddl.auto is set to create the table will be created every time when java class is Run.The old records will be deleted.

<property name="hbm2ddl.auto">create</property>

When set to update the records will be added without new table creation

<property name="hbm2ddl.auto">update</property>

More Annotations

3

@Transient tells not to create Column
@Column tells the Hibernate the Name under which column need to be
created in Db table.

@Transient 
@Column (name="User_Name") 
private String userName; 

@Temporal tells the option of selective addition.Below I am adding Date rather than
Date & time as Timestamp

 @Temporal (TemporalType.DATE) 
 private Date DOJ;

@Lob – Large Object, Telling Hibernate to create Large Object Datatype fro Column
@Lob over String creates CLOB
@Lob over Byte creates BLOB

 @Lob
 private String userDescription;

Comments are closed.