Hibernate - Interview Questions and Answers for 'Hibernate' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Interview Questions and Answers - Order By Newest

next 30
 Q11. What is the purpose of dialect configured in Hibernate configuration file ?Hibernate
Ans. It tells the framework which SQL varient to generate.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   orm   hibernate configuration


 Q12. Please specify in what sequence the objects of following classes will be created ?

Session , SessionFactory, Query , Configuration
Hibernate
Ans. Configuration -> SessionFactory -> Session -> Query

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate


Very frequently asked Hibernate interview question. Frequently asked in TCS ( based on 2 feedback )
  Q13. What are different types of associations in Hibernate ?Hibernate
Ans. There are 4 types of associations in Hibernate

One to One
One to Many
Many to One
Many to Many

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   associations     Asked in 11 Companies        frequent


 Q14. What are the configuration files in Hibernate ?Hibernate
Ans. hibernate.cfg.xml ( Main Configuration File )

and *.hbm.xml files ( Mapping Files )

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   configuration   mapping files


 Q15. What are the Core Interfaces of Hibernate Framework ? Hibernate
Ans. Configuration
SessionFactory
Session
Transaction
Query and Citeria

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate


 Q16. What are collection types in Hibernate ?Hibernate
Ans. Bag, Set , List , Array, Map

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate


Very frequently asked if being interviewed for hibernate. Frequently asked in Tata Consultancy (TCS) and Overstock.com
  Q17. Difference between load and get ?Hibernate
Ans. If id doesnt exist in the DB load throws an exception whereas get returns null in that case.get makes the call to DB immediately whereas load makes the call to proxy.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate     Asked in 16 Companies      basic        frequent


 Q18. What is the way to rollback transaction if something goes wrong using hibernate API ? Hibernate
Ans. We can have the code calling Hibernate API within try block and can have transaction.rollback within Catch.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   hibernate rollback


 Q19. What are the restrictions for the entity classes ?Hibernate
Ans. 1. Entity classes should have default constructor.

2. Entity classes should be declared non final.

3. All elements to be persisted should be declared private and should have public getters and setters in the Java Bean style.

4. All classes should have an ID that maps to Primary Key for the table.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   entity classes hibernate


 Q20. What are some differences between Spring caching and Hibernate caching?Hibernate
Ans. Spring caching makes use of its intercepting capabilities to add caching to method calls. Therefore, the entire object is cached and reused. Hibernate, on the other hand, has more domain-specific knowledge of the Entity being cached and can handle the objects more appropriately.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     spring framework   hibernate   spring cache   hibernate cache


 Q21. Do you like Native SQL Apis like JDBC or JPA / Hibernate ?Hibernate
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     JDBC vs JPA  JDBC vs Hibernate


 Q22. What are the the methods to clear cache in Hibernate ?Hibernate
Ans. Evict() and clear(). Evist is used to clear a particular object from the cache whereas clear clears the complete local cache.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   orm   hibernate cache


 Q23. What are different types of second level cache ?Hibernate
Ans. 1. EHCache ( Easy Hibernate )
2. OSCache ( Open Symphony )
3. Swarm Cache ( JBoss )
4. Tree Cache ( JBoss )

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   orm   hibernate cache   technical lead     Asked in 7 Companies


 Q24. Can we disable first level cache ? What should one do if we don't want an object to be cached ?Hibernate
Ans. No.We can either call evict after the object retrieval or can use separate sessions.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   orm   hibernate cache   architecture


 Q25. What is Hibernate ?Hibernate
Ans. Hibernate is a Java ORM Framework.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   orm   frameworks   architecture


 Q26. What are the different types of inheritance in Hibernate ?Hibernate
Ans. Table Per Class , Table per Sub Class , Table per Concrete Class

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   orm   inheritance hibernate     Asked in 1 Companies      Basic        frequent


  Q27. What is lazy fetching in Hibernate ?Hibernate
Ans. Lazy fetching is the technique of not loading the child objects when parent objects are loaded. By default Hibernate does not load child objects. One can specify whether to load them or not while doing the association.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   lazy fetching   architecture     Asked in 11 Companies        frequent

Try 2 Question(s) Test


 Q28. Different types of Hibernate Instance States ?Hibernate
Ans. Transient - In this state, an instance is not associated with any persistence context
Persistent - In this state, an instance is associated with a persistence context
Detached - This is a state for an instance which was previously associated with a persistence context an has been currently closed dissociated

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate


 Q29. Which class elements are not persisted ?Hibernate
Ans. Static and Transient.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   orm


 Q30. What entries we make in the hibernate config file if we are not using hbm files but Annotations ?Hibernate
Ans. We configure Entity classes having annotated mappings.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   hibernate annotations


 Q31. How many SessionFactory and Session objects are created ?Java EE
Ans. Single SessionFactory object and multiple session objects for opening different session. Hibernate creates new Session object per thread.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   sessionfactory hibernate   session hibernate


 Q32. What is the use of hbm2ddl Configuration in Hibernate ?Hibernate
Ans. This configuration specifies if hibernate should creates the Schema / Table on its own if the respective table is not found.

"update" doesn't create the table if it's not found whereas configuration set as "create" creates the schema automatically.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   hibernate configuration   hibernate.cfg.xml   hbm2ddl


 Q33. What is the difference between these 2 annotations ?

@Entity

@Entity ( name="EMPLOYEES" )
Hibernate
Ans. The first annotation will try to map the Class with the Table as of same name as Class whereas the second annotation will specify the Entity name as "EMPLOYEES" and hence will try to map with Table Name "EMPLOYEES".

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   hibernate annotations   entity annotations


 Q34. What is the difference between these 2 annotations ?

@Entity ( name ="EMPLOYEES")
@Entity @Table ( name=""EMPLOYEES"" )

@Entity ( name="EMP")
@Table ( name="EMPLPYEES" )
Hibernate
Ans. First Annotation will set the Entity name as EMPLOYEES and hence will try to map with the same Table name.

The second annotation will make the Entity mapped to table EMPLOYEES irrespective of the Entity Name ( which is class name in this case ).

Third Annotations will set the different names for Enitity and Table and will explicitly map them.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   hibernate annotations   entity annotation   table annotation


 Q35. What are the different ID generating strategies using @GeneratedValue annotation ?Hibernate
Ans. Auto , Identity , Sequence and Table.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   generatedvalue annotations   architecture


 Q36. How to do Eager loading in Hibernate ?Hibernate
Ans. Using

lazy = false in hibernate config file

or

@Basic(fetch=FetchType.EAGER) at the mapping

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   lazy loading hibernate   basic annotation hibernate   architecture


 Q37. What is cascade ?Hibernate
Ans. Instead of Saving Parent as well as Child Entities individually , Hibernate provides the option to persist / delete the related entities when the Parent is persisted.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   cascade   hibernate relationship   hibernate associations


 Q38. What are the different Cascade types ?Hibernate
Ans. Detach, Merge , Persist , Remove , Refresh

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   cascade   cascade type


 Q39. Which type of associated Entities are Eagerly loaded by Default ?Hibernate
Ans. OneToOne

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   hibernate associations   hibernate relationship


 Q40. After which Hibernate version , related Entities are initialized lazily ?Hibernate
Ans. After Hibernate 3.0

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   lazy loading hibernate   lazy initialization hibernate


next 30

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: