1.

What is a hibernate xml mapping document and what does it look like?

Answer»

Concurrency strategies act as mediators. They are responsible for storing items to and retrieving them from the cache. If the developer wants to enable a second level cache, the developer MUST decide to do it for each persistent class and collection. The developer must also decide which cache concurrency has to be implemented.  

The concurrency strategies that can be implemented by the developer are as follows: 

  • TRANSACTIONALThis strategy is used to read data where it is critical to prevent stale data in concurrent transactions especially in case of an update. 
  • Read - Only: This strategy is compatible with the reference data i.e. the data that can’t be modified. 
  • Read - Write: This strategy is similar to transactional strategy where it is critical to prevent stale data. 
  • Non-strict-Read-Write: There is no guarantee of consistency between database and cache when this strategy is used. This strategy is used only if data is modifiable and a small amount of stale data is not a critical concern. 

These strategies are used with second - level cache. An EXAMPLE of the usage of these strategies is shown in the below example where we add a mapping element to the configuration file to inform Hibernate to cache the persistent class instances using read-write strategy. We are using the Employee class in this example. 

<hibernate-mapping>            <class name = "Employee" table = "EMPLOYEE">                  <meta attribute = "class-description">                      This class contains the employee DETAIL.                   </meta>                  <cache usage = "read-write"/>                  <id name = "id" type = "int" COLUMN = "id">                      <generator class="native"/>                  </id>                  <property name = "firstName" column = "first_name" type = "string"/>                  <property name = "lastName" column = "last_name" type = "string"/>                  <property name = "salary" column = "salary" type = "int"/>           </class>       </hibernate-mapping>


Discussion

No Comment Found