Tuesday, 26 June 2012

Hibernate FAQs-->3

Hibernate Interview Questions And Answers


41.Define cascade and inverse option in one-many mapping?


cascade - enable operations to cascade to child entities.
cascade="all|none|save-update|delete|all-delete-orphan"

inverse - mark this collection as the "inverse" end of a bidirectional association.
inverse="true|false"
Essentially "inverse" indicates which end of a relationship should be ignored, so when persisting a parent who has a collection of children, should you ask the parent for its list of children, or ask the children who the parents are?

42 . Explain about transaction file?


Transactions denote a work file which can save changes made or revert back the changes. A transaction can be started by session.beginTransaction() and it uses JDBC connection, CORBA or JTA. When this session starts several transactions may occur.

43 . Difference between session.save() , session.saveOrUpdate() and session.persist()?


All methods are used to store the data in to database
            session.save() : save() method uSave does an insert and will fail if the primary key is already persistent.
session.saveOrUpdate() : saveOrUpdate() insert the data in the database if that primary key data not available and it update the data if primary key data not availabt
session.persist() :it is the same like session.save(). But session.save() return Serializable object but session.persist() return void.
For Example :
         if you do :-
         System.out.println(session.save(question));
         This will print the generated primary key.
         if you do :-
        
System.out.println(session.persist(question));
         Compile time error because session.persist() return void.

44 . Explain about the id field?

This id field is used to configure the primary key in the mapping file, and also we can configure primary key generation algorithm.

45.What is the use of dynamic-insert and dynamic-update attributes in a class mapping?


Criteria is a simplified API for retrieving entities by composing Criterion objects. This is a very convenient approach for functionality like "search" screens where there is a variable number of conditions to be placed upon the result set.
  · dynamic-update (defaults to false): Specifies that UPDATE SQL should be generated at runtime and contain only those columns whose values have changed
  · dynamic-insert (defaults to false): Specifies that INSERT SQL should be generated at runtime and contain only the columns whose values are not null.

46.What is automatic dirty checking?


Automatic dirty checking is a feature that saves us the effort of explicitly asking Hibernate to update the database when we modify the state of an object inside a transaction.

47.What are Callback interfaces?


Callback interfaces allow the application to receive a notification when something interesting happens to an object—for example, when an object is loaded, saved, or deleted. Hibernate applications don't need to implement these callbacks, but they're useful for implementing certain kinds of generic functionality.

48.What is Hibernate proxy?


The proxy attribute enables lazy initialization of persistent instances of the class. Hibernate will initially return CGLIB proxies which implement the named interface. The actual persistent object will be loaded when a method of the proxy is invoked.

49.How can Hibernate be configured to access an instance variable directly and not through a 
setter method ?


By mapping the property with access="field" in Hibernate metadata. This forces hibernate to bypass the setter method and access the instance variable directly while initializing a newly loaded object.

50.How can a whole class be mapped as immutable?


Mark the class as mutable="false" (Default is true),. This specifies that instances of the class are (not) mutable. Immutable classes, may not be updated or deleted by the application.

51 .  Explain about transparent persistence of Hibernate?

Transparent persistence is provided for Plain old Java objects or POJOs. For proper functioning of the applications importance should be given to the methods equals () and hash Code methods (). It has a requirement which should be strictly followed in the applications which is a no-argument constructor.

52 .  Explain about the dirty checking feature of Hibernate?

Dirty checking feature of the Hibernate allows users or developers to avoid time consuming data base write actions. This feature makes necessary updations and changes to the fields which require a change, remaining fields are left unchanged or untouched.

53 .  What is the effect when a transient mapped object is passed onto a Sessions save?

When a Sessions save () is passed to a transient mapped object it makes the method to become more persistent. Garbage collection and termination of the Java virtual machine stays as long as it is deleted explicitly. It may head back to its transient state.

54 .  Explain about addClass function?


This function translates a Java class name into file name. This translated file name is then loaded as an input stream from the Java class loader. This addClass function is important if you want efficient usage of classes in your code.

0 comments:

Post a Comment