*evict(): evict() method is used to remove a specified object from the 1st level cache.

Ex

Transaction tx = hsession.beginTransaction();
hsession.load(e,new BigDecimal(1));
e.setName(“Raju”);
hsession.evict(e);
tx.commit();

When we run the above application with out evict() method. It has update a record into database server. When we run the some application with evict() method. It has removed employee object from 1st level cache.

*merge()
merge method is used to add a specified object to the 1st level cache.

Ex:

Emp e = new Emp();
e.setEno(new BigDecimal(22));
e.setName(“ABC modified”);
e.setSalary(1234d);
hsession.merge(e);
tx.commit();

When the merge() method is called the object is added to 1st level cache without registration code. When tx.commit() method is called it will get the object which does not contain the registration code. It will check weather the object is available in database server by sending select query. If the record is not available it will send an insert query to database server. If the record is already available it will send a an update query to database server.

*There three states are available to hibernate objects they are:
1. Transient
2. Persistent
3. Detached

Transient: An object is which is not associated with any session object.
Persistent: An object which is added to 1st level cache is called as persistent state.
Detached: An object which is removed from 1st level cache is called detached state.

*Clear():
                Clear is used to remove all the objects from 1st level cache. This will remove unperformed operations like save and update also. The clear() method will evict all available objects.

0 comments:

Post a Comment