Interview Questions and Answers - Order By Newest Q61. What does the following exception means
org.hibernate.LazyInitializationException: could not initialize proxy - no Session Hibernate
Ans. The error states that Hibernate is not able to initialize proxy / dependent entity objects as there is no session or transaction present. Very likely we are trying to load the dependent entities lazily but the call to dependent object property is not wrapped within the session or transaction. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  Lazy Loading  Lazy Initialization  org.hibernate.LazyInitializationException Q62. If you are given choice to avoid LazyInitializationException using any of the following measures, which are the ones you will choose and why ?
1. Set lazy=false in the hibernate config file.
2. Set @Basic(fetch=FetchType.EAGER) at the mapping.
3. Make sure that we are accessing the dependent objects before closing the session.
4. Force initialization using Hibernate.initialize Hibernate
Ans. First resolution is a big No as it conveys no lazy loading in complete app. even second is advocating the same but for a particular mapping.
third one is most appropriate if loading and dependent entity property access is closer to each other in code and can be accomplished.
I don't mind using 4th too. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  lazy loading  lazy initialization  LazyInitializationException Q63. What was the worst problem you faced while working with Hibernate ? Hibernate
Ans. Lazy Initialization exceptions Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q64. Is it advisable to keep session or transaction open for long time just to avoid LazyInitializationException ? Hibernate
Ans. No. It's a resource and performance overhead. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  LazyInitializationException  Lazy Loading Q65. Does Hibernate synchronize entity with the database automatically i.e any change to entity gets updated in DB ? Hibernate
Ans. Yes, the feature is there but can be override with changing the Flush Mode. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q66. How can we make sure that Hibernate doesn't update the entity changes to DB or how to keep the entity detached ? Hibernate
Ans. If it's only a read only transaction, we can wrap the get / load call in read only transaction.
If we want it to be application wide, we an set the flush mode accordingly or else we can evict the entity object to remove them from session. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Try 2 Question(s) Test Q67. What is the difference between session.clear and session.evict ? Hibernate
Ans. session.clear clears all the objects from session whereas session.evict is used for evicting a particular entity. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate session clear  hibernate evict Try 2 Question(s) Test Q68. What is the use of Hibernate session.clear() ? Hibernate
Ans. It is used to clear the session and is used to dissociate disconnect all the objects from the session. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate session clear Q69. What is the use of Hibernate session.evict()? Hibernate
Ans. It is used to dissociate / disconnect a particular object from the session. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate session evict  hibernate evict Q70. What are the core interfaces in Hibernate? Hibernate
Ans. Session,SessionFactory,Configuration,Transaction,query and Criteria Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  core interfaces of Hibernate Asked in 1 Companies   frequent Try 1 Question(s) Test Q71. What is ConstraintViolationException in Hibernate ? Hibernate
Ans. The exception is thrown when a database constraint is violated. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  ConstraintViolationException Q72. What could be the possible cause for following exception ?
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect):
What could be the way to fix it ? Hibernate
Ans. This looks like the case for optimistic locking wherein hibernate suspects that the information in table was updated by some other transaction after the entity was loaded by current transaction.
One way is to have synchronized entity state and don't detach the entity. Other could be to merge the entity with the table record rather than just directly persisting the entity. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  StaleObjectStateException  Optimistic locking Q73. What is the difference between JDBC, Hibernate and ODBC ? Database
This question was recently asked at 'Oracle Argentina'.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  odbc  hibernate  jdbc vc odbc  jdbc vs hibernate Asked in 1 Companies This question was recently asked at 'Sofi'.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  hibernate  hibernate validation Asked in 1 Companies Q75. What is meant by dirty object checking in hibernate ? Hibernate
Ans. Dirty Checking is one of the features of hibernate. In dirty checking, hibernate automatically detects whether an object is modified (or) not and need to be updated. As long as the object is in persistent state i.e., bound to a particular Session, Hibernate monitors any changes to the objects and executes sql. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  dirty checking in hibernate Asked in 1 Companies Q76. Can you write the code for implementing the one to many (student -> courses) relationship in hibernate? Hibernate
Ans. @OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "student_id")
private Set countries; Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q77. What is difference between Spring jdbc template and 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  Spring JDBC vs Hibernate  Spring JDBC   Hibernate Q78. What is the use of second level cache in Hibernate ? Hibernate
Ans. Second level cache is shared between sessions. Hibernate by default uses first level cache. Second level cache need to be configurd to use.
There are several second level cache e.g eh cache,jboss cache etc. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q79. Difference between Eager and Lazy loading in hibernate ? Hibernate
Ans. Lazy Loading is loading of entities on demand when subclass is called, while Eager loading is loading of all the sub entity at the start only.
Eager loading is fast as all sub entities are already present, but its heavy(takes more memory) Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q80. What is the difference between save() and persist() in hibernate ? Hibernate
This question was recently asked at 'IBM'.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   Asked in 1 Companies Q81. If your application has multiple databases, how many changes you have to made in Hibernate? Hibernate
Ans. If you have mulitple Databases you just need to add multiple configuration files and create the corresponding SessionFactory object. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q82. What is the use of sql dialect ? Hibernate
Ans. Dialect means "the variant of a language".
Similarly in case of SQL Dialect we specify what dialect of SQL to be generated keeping in mind of underlying database. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  sql dialect  hibernate   hibernate Asked in 2 Companies Q83. Which jar files need to be included for using Hibernate ? Hibernate
Ans. hibernate-orm
hibernate-validator
hibernate-ogm
hibernate-search
or you can download hibernate core with all dependencies. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate jar files   hibernate Asked in 1 Companies This question was recently asked at 'naresh i technologies'.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   Asked in 1 Companies Q85. Explain hibernate associations. Hibernate
This question was recently asked at 'Ray Business Technologies'.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   Asked in 1 Companies Q86. Explain Hibernate caching mechanism Hibernate
Ans. Every fresh session having its own cache memory, Caching is a mechanism for storing the loaded objects into cache memory. The advantage of cache mechanism is, whenever again we want to load the same object from the database then instead of hitting the database once again, it loads from the local cache memory only, so that the no. of round trips between an application and a database server got decreased. It means caching mechanism increases the performance of the application.
In hibernate we have two levels of caching
First Level Cache [ or ] Session Cache
Second Level Cache [ or ] Session Factory Cache [ or ] JVM Level Cache Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 23 Companies Q87. Explain different inheritance mapping strategies with JPA / Hibernate. Hibernate
Ans. table per hierarchy
table per concrete class
table per sub class Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate mapping  hibernate associations Asked in 4 Companies Q88. What is the concept of hibernate versioning ? Hibernate
This question was recently asked at 'Tata Consultancy (TCS)'.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  hibernate versioning Asked in 1 Companies This question was recently asked at 'NIIT'.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   Asked in 1 Companies Q90. what annotation do in background in hibernate ? Hibernate
This question was recently asked at 'Cdac Pune'.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   Asked in 1 Companies