Monday, September 18, 2017

Basics about hibernate

Small Snippet of hibernate.cfg.xml

<hibernate-configuration>
       <session-factory>

       <property name="hibernate.transaction.auto_close_session">true</property>
       <property name="hibernate.transaction.flush_before_completion">true</property>
       <property name="hibernate.cache.use_second_level_cache">false</property>

       <mapping resource="com/mmoney/model/SysMessagesDTO.hbm.xml" />

       </session-factory>
</hibernate-configuration>

com.mmoney.dto.SysMessagesDTO.java

<hibernate-mapping>
       <class name="com.mmoney.dto.SysMessagesDTO"  table="SYS_MESSAGES">
              <composite-id>
                     <key-property name="messageCode" column="MESSAGE_CODE" />
                     <key-property name="languageCode"
                     column="LANGUAGE_CODE" type="java.lang.Long"/>
              </composite-id>
      
              <property name="message" column="MESSAGE" />
              <property name="application" column="APPLICATION" />
              <property name="linked" column="LINKED" />
              <property name="messageParam" column="MESSAGE_PARAM" />
             
       </class>
</hibernate-mapping>

JPA offers 4 different ways to generate primary key values:
1.     AUTO: Hibernate selects the generation strategy based on the used dialect,
2.     IDENTITY: Hibernate relies on an auto-incremented database column to generate the primary key
3.     SEQUENCE: Hibernate requests the primary key value from a database sequence
4.     TABLE: Hibernate uses a database table to simulate a sequence.


No comments:

Post a Comment