The largest Interview Solution Library on the web


Interview Questions
« Previous | 0 | 1 | 2 | 3 | 4 | Next »

81.What are the ways to express joins in HQL?

HQL provides four ways of expressing (inner and outer) joins:-
• An implicit association join
• An ordinary join in the FROM clause
• A fetch join in the FROM clause.
• A theta-style join in the WHERE clause.

82.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?

83.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.

84.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.

85.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.

86.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.

87.What do you mean by fetching strategy ?

A fetching strategy is the strategy Hibernate will use for retrieving associated objects if the application needs to navigate the association. Fetch strategies may be declared in the O/R mapping metadata, or over-ridden by a particular HQL or Criteria query.

88.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.

89.What is transactional write-behind?

Hibernate uses a sophisticated algorithm to determine an efficient ordering that avoids database foreign key constraint violations but is still sufficiently predictable to the user. This feature is called transactional write-behind.

90.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.

91.What are the types of Hibernate instance states ?

Three types of instance states:
• Transient -The instance is not associated with any persistence context
• Persistent -The instance is associated with a persistence context
• Detached -The instance was associated with a persistence context which has been closed – currently not associated

92.What are the types of inheritance models in Hibernate?

There are three types of inheritance models in Hibernate:
• Table per class hierarchy
• Table per subclass
• Table per concrete class

93.Is SessionFactory a thread-safe object?

Yes, SessionFactory is a thread-safe object, many threads cannot access it simultaneously.

94.What is Session?

It maintains a connection between hibernate application and database. It provides methods to store, update, delete or fetch data from the database such as persist(), update(), delete(), load(), get() etc. It is a factory of Query, Criteria and Transaction i.e. it provides factory methods to return these instances.

95.Is Session a thread-safe object?

No, Session is not a thread-safe object, many threads can access it simultaneously. In other words, you can share it between threads.

96.What are the states of object in hibernate?

There are 3 states of object (instance) in hibernate.
18 Transient: The object is in transient state if it is just created but has no primary key (identifier) and not associated with session.
19 Persistent: The object is in persistent state if session is open, and you just saved the instance in the database or retrieved the instance from the database.
20 Detached: The object is in detached state if session is closed. After detached state, object comes to persistent state if you call lock() or update() method.

97.What are the inheritance mapping strategies?

There are 3 ways of inheritance mapping in hibernate.
21 Table per hierarchy
22 Table per concrete class
23 Table per subclass

98.How to make a immutable class in hibernate?

If you mark a class as mutable="false", class will be treated as an immutable class. By default, it is mutable="true".

99.What is automatic dirty checking in hibernate?

The automatic dirty checking feature of hibernate, calls update statement automatically on the objects that are modified in a transaction. Let's understand it by the example given below:
25 SessionFactory factory = cfg.buildSessionFactory();
26 Session session1 = factory.openSession();
27 Transaction tx=session2.beginTransaction();
28
29 Employee e1 = (Employee) session1.get(Employee.class, Integer.valueOf(101));
30
31 e1.setSalary(70000);
32
33 tx.commit();
34 session1.close();
Here, after getting employee instance e1 and we are changing the state of e1. After changing the state, we are committing the transaction. In such case, state will be updated automatically. This is known as dirty checking in hibernate.

100.How many types of association mapping are possible in hibernate?

There can be 4 types of association mapping in hibernate.
35 One to One
36 One to Many
37 Many to One
38 Many to Many

« Previous | 1 | 2 | 3 | Next »


copyright © 2014 - all rights riserved by javatechnologycenter.com