Hibernate Interview Questions

21 .How do you define sequence generated primary key in hibernate?

Using <generator> tag.

Example:
<id column="USER_ID" name="id" type="java.lang.Long">
   <generator class="sequence"> 
     <param name="table">SEQUENCE_NAME</param>
   <generator>
</id>

22.What are the Collection types in Hibernate ?

  • Bag
  • Set
  • List
  • Array
  • Map

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

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

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