Showing posts with label ORM. Show all posts
Showing posts with label ORM. Show all posts
Hibernate is a powerful object relational mapping tool written in Java. Hibernate allows you to develop persistent classes mirroring object oriented paradigm - including association, inheritance, polymorphism, composition, and collections. Hibernate has its own portable SQL based langugage (HQL) or can work with native SQL. Hibernate simplifies persistence programming tasks by providing a higher abstraction.

Hibernate is a suite of tools for ORM, including Hibernate core, Hibernate Tools, Hibernate search etc. Only core is required for basic ORM. Each component is available as a separate download.
Hibernate stores table to class mapping in an external XML file. Following is a sample,
<hibernate-mapping>
    <class name=”tasks.Task” table=”TASKS”>
        <id name=”id” column=”TASK_ID”>
            <generator class=”native”/>
        </id>
        <property name=”date” type=”timestamp” column=”TASK_DATE”/>
        <property name=”title”/>
    </class>
</hibernate-mapping>
While working with Hibernate web applications we will face so many problems in its performance due to database traffic. That to when the database traffic is very heavy . Actually hibernate is well used just because of its high performance only. So some techniques are necessary to maintain its performance. Caching is the best technique to solve this problem. In this article we will discuss about, how we can improve the performance of Hibernate web applications using caching.
 Hibernate uses two different caches for objects: first-level cache and second-level cache..
1.1) First-level cache
First-level cache always Associates with the Session object. Hibernate uses this cache by default. Here, it processes one transaction after another one, means wont process one transaction many times. Mainly it reduces then number of SQL queries it needs to generate within a given transaction. That is instead of updating after every modification done in the transaction, it updates the transaction only at the end of the transaction.
1.2) Second-level cache
Second-level cache always associates with the Session Factory object. While running the transactions, in between it loads the objects at the Session Factory level, so that those objects will available to the entire application, don’t bounds to single user. Since the objects are already loaded in the cache, whenever an object is returned by the query, at that time no need to go for a database transaction. In this way the second level cacheworks. Here we can use query level cache also. Later we will discuss about it.

2) Cache Implementations

Hibernate supports four open-source cache implementations named EHCache (Easy Hibernate Cache), OSCache (Open Symphony Cache), Swarm Cache, and JBoss Tree Cache. Each cache has differentperformance, memory use, and configuration possibilities.
2.1)2.1EHCache(EasyHibernateCache) (org.hibernate.cache.EhCacheProvider)
  • It is fast.
  • lightweight.
  • Easy-to-use.
  • Supports read-only and read/write caching.
  • Supports memory-based and disk-based caching.
  • Does not support clustering.
2.2)OSCache(OpenSymphonyCache) (org.hibernate.cache.OSCacheProvider)
  • It is a powerful .
  • flexible package
  • supports read-only and read/write caching.
  • Supports memory- based and disk-based caching.
  • Provides basic support for clustering via either JavaGroups or JMS.
2.3)SwarmCache (org.hibernate.cache.SwarmCacheProvider)
  • is a cluster-based caching.
  • supports read-only or nonstrict read/write caching .
  • appropriate for applications those have more read operations than write operations.
2.4)JBoss TreeCache (org.hibernate.cache.TreeCacheProvider)
  • is a powerful replicated and transactional cache.
  • useful when we need a true transaction-capable caching architecture .
LiveJournal Tags: ,
Technorati Tags: ,

In every hibernate mapping files, we used to denote the “type” of the mapping variable. This type is actually known as Hibernate mapping types.
These are very much different from SQL database types as well as Java data types. Here you can find a list of Hibernate mapping types. Source : here

integer, long, short

Java primitives or wrapper classes to appropriate (vendor-specific) SQL column types.

float, double

Java primitives or wrapper classes to appropriate (vendor-specific) SQL column types.

character, byte

Java primitives or wrapper classes to appropriate (vendor-specific) SQL column types.

boolean, yes_no, true_false

Alternative encodings for a Java boolean or java.lang.Boolean

string

java.lang.String to VARCHAR (or Oracle VARCHAR2).

date, time, timestamp

java.util.Date and its subclasses to SQL types DATE, TIME and TIMESTAMP (or equivalent).

calendar, calendar_date

java.util.Calendar to SQL types TIMESTAMP and DATE (or equivalent).

big_decimal, big_integer

java.math.BigDecimal and java.math.BigInteger to NUMERIC (or Oracle NUMBER).

locale, timezone, currency

java.util.Locale, java.util.TimeZone and java.util.Currency to VARCHAR (or Oracle VARCHAR2). Instances of Locale and Currency are mapped to their ISO codes. Instances of TimeZone are mapped to their ID

class

java.lang.Class to VARCHAR (or Oracle VARCHAR2). A Class is mapped to its fully qualified name.

binary

Maps byte arrays to an appropriate SQL binary type.

text

Maps long Java strings to a SQL CLOB or TEXT type.

serializable

Maps serializable Java types to an appropriate SQL binary type. You may also indicate the Hibernate type serializable with the name of a serializable Java class or interface that does not default to a basic type.

clob, blob

Type mappings for the JDBC classes java.sql.Clob and java.sql.BlobThese types may be inconvenient for some applications, since the blob or clob object may not be reused outside of a transaction. (Furthermore, driver support is patchy and inconsistent.)

Technorati: Hibernate

+