9:52 am - Tuesday February 28, 2017

Hibernate Interview Question9

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

1.            what is caching?

Anything you can do to minimize traffic between a database and an application server is probably a good thing. In theory, an application ought to be able to maintain a cache containing data already loaded from the database, and only hit the database when information has to be updated. When the database is hit, the changes may invalidate the cache

2.            Types of caching ?

  • First-Level Cache
  • Second-Level Cache

3.            What are the different options for hibernate second level of caching

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 entireapplication, 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 cache works. Here we can use query level cache also. Later we will discuss about it.

To activate second-level caching, you need to define the hibernate.cache.provider_class property in the hibernate.cfg.xml file as follows:

< hibernate-configuration >

< session-factory >

< property name=”hibernate.cache.provider_class” >org.hibernate.cache.EHCacheProvider< / property>

< / session-factory >

< / hibernate-configuration >

 

By default, the second-level cache is activated and uses the EHCache provider.

To use the query cache you must first enable it by setting the property hibernate.cache.use_query_cache to true in hibernate.properties.

4.            Explain the process nof achieving second level caching

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 cache works. Here we can use query level cache also. Later we will discuss about it.

5.            What is evict and close?

Hibernate does a neat trick where it tracks objects that have been changes since being loaded from the database. Once Hibernate provides an object, make a modification and flush the Session – Hibernate knows the object was changed and will propagate to the database accordingly.

6.            what are managed associations and hibernate associations

Associations that are related to container management persistence are called managed associations. These are bi-directional associations. Coming to hibernate associations, these are unidirectional

7.            What are the different approaches to represent an inheritance hierarchy?

  • Table per concrete class.
  • Table per class hierarchy.
  • Table per subclass.

8.            What are the different methods of identifying an object?

There are three methods by which an object can be identified.

  • Object identity – Objects are identical if they reside in the same memory location in the JVM. This can be checked by using the = = operator.
  • Object equality – Objects are equal if they have the same value, as defined by the equals( ) method. Classes that don’t explicitly override this method inherit the implementation defined by java.lang.Object, which compares object identity.
  • Database identity – Objects stored in a relational database are identical if they represent the same row or, equivalently, share the same table and primary key value.

9.            What is Attribute Oriented Programming?

XDoclet has brought the concept of attribute-oriented programming to Java. Until JDK 1.5, the Java language had no support for annotations; now XDoclet uses the Javadoc tag format (@attribute) to specify class-, field-, or method-level metadata attributes. These attributes are used to generate hibernate mapping file automatically when the application is built. This kind of programming that works on attributes is called as Attribute Oriented Programming.

10.          What are the different types of property and class mappings?

  • Typical and most common property mapping

<property name=”description” column=”DESCRIPTION” type=”string”/>

Or

<property name=”description” type=”string”>

<column name=”DESCRIPTION”/>

</property>

  • Derived properties

<property name=”averageBidAmount” formula=”( select AVG(b.AMOUNT) from BID b where b.ITEM_ID = ITEM_ID )” type=”big_decimal”/>

  • Typical and most common property mapping

<property name=”description” column=”DESCRIPTION” type=”string”/>

  • Controlling inserts and updates

<property name=”name” column=”NAME” type=”string” insert=”false” update=”false”/>

 

Filed in: Z-A Interview Questions

No comments yet.

Leave a Reply