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

Search Java Interview Questions


 2098 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Hibernate' - 83 question(s) found - Order By Newest

Frequently asked question in companies using Hibernate.
  Q1. What is Lazy Initialization in Hibernate ?Hibernate
Admin
info@buggybread.com
Ans. It's a feature to lazily initialize dependencies , relationship and associations from the Database. Any related references marked as @OneToMany or @ManyToMany are loaded lazily i.e when they are accessed and not when the parent is loaded.

 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   architecture     overstock.com  BridgePoint Technologies  Medgate  Dex Media  Diversant  Tieto  Oracle  Bank of America Merrill LYNCH  NEC Japan  HCL Technologies      Basic        frequent

Try 2 Question(s) Test


 Q2. What are the ways to avoid LazyInitializationException ?Hibernate
Admin
info@buggybread.com
Ans. 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

5. Using Fetch Join in HQL.

 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   lazyinitializationexception   architecture     Squelch  Overstock.com

Try 2 Question(s) Test


Frequently asked question in companies using hibernate.
  Q3. Difference between first level and second level cache in hibernate ?Hibernate
Admin
info@buggybread.com
Ans. 1. First level cache is enabled by default whereas Second level cache needs to be enabled explicitly.

2. First level Cache came with Hibernate 1.0 whereas Second level cache came with Hibernate 3.0.

3. First level Cache is Session specific whereas Second level cache is shared by sessions that is why First level cache is considered local and second level cache is considered global.

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

   Like      Discuss      Correct / Improve     hibernate   orm   hibernate cache   architecture   technical lead     EFI  Geometric  QuinStreet  Cognizant (CTS)  ZS Associates  Walt Disney      Intermediate        frequent


 Q4. How to configure second level cache in Hibernate ?Hibernate
Admin
info@buggybread.com
Ans. 1. Configure Provider class in Hibernate configuration file.

2. Add Cache usage tag ( read-only or read-write ) in mapping files ( hbm ).

3. Create an XML file called ehcache.xml and place in classpath which contains time settings and update settings, behavior of cache , lifetime and idletime of Pojos, how many objects are allowed.

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

   Like      Discuss      Correct / Improve     hibernate   orm   hibernate cache   architecture


 Q5. What are the contents of Hibernate configuration file ( hibernate.cfg.xml ) ?Hibernate
Admin
info@buggybread.com
Ans. HBM Files ( Mapping )
DB Connection ( DB Connection String , User Name , Password , Pool Size )
SQL Dialect ( SQL variant to be generated )
Show SQL ( Show / No show SQL on Console )
Auto Commit ( True / False )

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

   Like      Discuss      Correct / Improve     hibernate   configuration   barclays     Mphasis  Mccoy Global Links  Availity  Infosys  GlobalLogic  Cognizant (CTS)  Overstock.com  Erricson  Erricson India  HCL Technologies  Tata Consultancy (TCS)


 Q6. Which annotations are used in Hibernate ?Hibernate
admin
info@buggybread.com
Ans. @Entity
@Table
@Id
@Column
@Temporal
@Basic
@Enumerated
@Access
@Embeddable
@Lob
@AttributeOverride
@Embedded
@GeneratedValue
@ElementCollection
@JoinTable
@JoinColumn
@CollectionId
@GenericGenerator
@OneToOne
@OneToMany
@ManyToOne
@ManyToMany
@NotFound

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

   Like      Discuss      Correct / Improve     hibernate   annotations


 Q7. What is the purpose of dialect configured in Hibernate configuration file ?Hibernate
Admin
info@buggybread.com
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


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

Session , SessionFactory, Query , Configuration
Hibernate
Admin
info@buggybread.com
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


 Q9. What are the configuration files in Hibernate ?Hibernate
Admin
info@buggybread.com
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



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q10. What are the Core Interfaces of Hibernate Framework ? Hibernate
Admin
info@buggybread.com
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


 Q11. What are collection types in Hibernate ?Hibernate
Admin
info@buggybread.com
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
  Q12. Difference between load and get ?Hibernate
Admin
info@buggybread.com
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     Overstock.com  Nagarro  Anthem  Tata Consultancy (TCS)  Nucleus Software Exports  CDK Global  Dell  Capgemini  Persistent Systems  HCL Technologies  Nagarro  Sears  CDK Global  Oracle  Nucleus Software Exports  CACI International      basic        frequent


 Q13. What are the restrictions for the entity classes ?Hibernate
Admin
info@buggybread.com
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


 Q14. What things you would care about to improve the performance of Application if its identified that its DB communication that needs to be improved ?Solution
Admin
info@buggybread.com
Ans. 1. Query Optimization ( Query Rewriting , Prepared Statements )

2. Restructuring Indexes.

3. DB Caching Tuning ( if using ORM )

4. Identifying the problems ( if any ) with the ORM Strategy ( If using ORM )

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

   Like      Discuss      Correct / Improve     java   db   database   hibernate   orm   at&t   overstock.com   performance improvement   architecture   technical lead   architect      intermediate


 Q15. What is the use of @GeneratedValue annotation in Hibernate?Hibernate
Admin
info@buggybread.com
Ans. This annotation is added to the auto increment column with the strategy to increment the column value. Usually this is added to the surrogate primary key column and specified with the Database Sequence.

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

   Like      Discuss      Correct / Improve     hibernate   hibernate annotations   @generatedvalue   database sequence


 Q16. What are some differences between Spring caching and Hibernate caching?Hibernate
Admin
info@buggybread.com
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


 Q17. What are the the methods to clear cache in Hibernate ?Hibernate
Admin
info@buggybread.com
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


 Q18. What are different types of second level cache ?Hibernate
Admin
info@buggybread.com
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


 Q19. Can we disable first level cache ? What should one do if we don't want an object to be cached ?Hibernate
Admin
info@buggybread.com
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



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q20. What is Hibernate ?Hibernate
Admin
info@buggybread.com
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


 Q21. What are the advantages of Hibernate ?Hibernate
Admin
info@buggybread.com
Ans. 1. No need to know SQL, RDBMS, and DB Schema.
2. Underlying Database can be changed without much effort by changing SQL dialect and DB connection.
3.Improved Performance by means of Caching.

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

   Like      Discuss      Correct / Improve     hibernate   orm   architecture


 Q22. What are the different types of inheritance in Hibernate ?Hibernate
Admin
info@buggybread.com
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     Fidelity      Basic        frequent


Very frequently asked Hibernate interview question.
  Q23. What are different types of associations in Hibernate ?Hibernate
Admin
info@buggybread.com
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     Overstock.com  BirlaSoft  Fiserv  Overstock.com  Tata Consultancy (TCS)  Wipro  Tech Mahindra  Infosys  HCL Technologies  Fidelity  Sabre        frequent


  Q24. What is lazy fetching in Hibernate ?Hibernate
Admin
info@buggybread.com
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     Aldo  Rent the Runway  Veteran Corps  United Health Group (UHG)  Medgate  Prokarma  Mars Telecom Systems  Dun & Bradstreet  Kumaran Systems  Tavant Technologies  CaseNet        frequent

Try 2 Question(s) Test


 Q25. Different types of Hibernate Instance States ?Hibernate
Admin
info@buggybread.com
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


 Q26. Which class elements are not persisted ?Hibernate
admin
info@buggybread.com
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


 Q27. What entries we make in the hibernate config file if we are not using hbm files but Annotations ?Hibernate
Admin
info@buggybread.com
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


 Q28. How many SessionFactory and Session objects are created ?Java EE
Admin
info@buggybread.com
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


 Q29. What is the way to rollback transaction if something goes wrong using hibernate API ? Hibernate
Admin
info@buggybread.com
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



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q30. What is the use of hbm2ddl Configuration in Hibernate ?Hibernate
Admin
info@buggybread.com
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


 Q31. What is the difference between these 2 annotations ?

@Entity

@Entity ( name="EMPLOYEES" )
Hibernate
admin
info@buggybread.com
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


 Q32. What is the difference between these 2 annotations ?

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

@Entity ( name="EMP")
@Table ( name="EMPLPYEES" )
Hibernate
Admin
info@buggybread.com
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


 Q33. What are the different ID generating strategies using @GeneratedValue annotation ?Hibernate
Admin
info@buggybread.com
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


 Q34. How to do Eager loading in Hibernate ?Hibernate
Admin
info@buggybread.com
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


 Q35. What is cascade ?Hibernate
Admin
info@buggybread.com
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


 Q36. What are the different Cascade types ?Hibernate
Admin
info@buggybread.com
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


 Q37. Which type of associated Entities are Eagerly loaded by Default ?Hibernate
Admin
info@buggybread.com
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


 Q38. After which Hibernate version , related Entities are initialized lazily ?Hibernate
admin
info@buggybread.com
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


 Q39. Can we declare Entity class as final ?Hibernate
Admin
info@buggybread.com
Ans. Yes but as Hibernate creates the Proxy Classes inherited from the Entity Classes to communicate with Database for lazy initialization. Declaring entity classes as final will prohibit communication with database lazily and hence will be a performance hit.

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

   Like      Discuss      Correct / Improve     hibernate   proxy objects   proxy classes   entity hibernate



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q40. What is the difference between JPA and Hibernate ?Hibernate
Admin
info@buggybread.com
Ans. JPA or Java Persistence API is a standard specification for ORM implementations whereas Hibernate is the actual ORM implementation or framework.

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

   Like      Discuss      Correct / Improve     jpa   hibernate   orm   architecture   technologies     Wizni  Naggaro


 Q41. What is the advantage of JPA ?Database
Admin
info@buggybread.com
Ans. Its a specification that guides the implementation of ORM frameworks. Implementations abiding by the specification would mean that one can be replaced with other in an application without much hassle. Only the Features that are added over the specification needs to be taken care of if any such change is made.

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

   Like      Discuss      Correct / Improve     jpa   hibernate   orm   technologies


 Q42. What is Criteria in Hibernate ?Hibernate
Admin
info@buggybread.com
Ans. Criteria is a simplified API for retrieving entities by composing Criterion objects.

For example - session.createCriteria(Employee.class).add( Restrictions.like("name", "A%") ).list();

will return all employee objects having name starting with A.

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

   Like      Discuss      Correct / Improve     hibernate   hibernate criteria

Try 1 Question(s) Test


 Q43. How do we specify the criteria if it involves mapping between two entities or join between tables ?Hibernate
Admin
info@buggybread.com
Ans. The following code returns the list of Employee objects having employee name starting with A and Dept Name ( Department , Employee Mapped ).

session.createCriteria(Employee.class,"emp")
.createAlias("emp.department", "dept",Criteria.INNER_JOIN)
.add( Restrictions.like("name", "A%") )
.add(Restrictions.eq("dept.name","Finance")
.list();

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

   Like      Discuss      Correct / Improve     hibernate   hibernate criteria   hibernate table mapping


 Q44. Name few Restriction Methods ?Hibernate
Admin
info@buggybread.com
Ans. eq, ge, gt , between, in , isNull, isEmpty, isNotnull, ne , like, lt , or , not

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

   Like      Discuss      Correct / Improve     hibernate   hibernate criteria   hibernate restriction


 Q45. In Hibernate, While defining Criteria, Have you ever faced any problem while adding restrictions with user defined types or Enums ?Hibernate
Admin
info@buggybread.com
Ans. Yes, with Enum as was getting an exception while doing equality check for enum field.

got it fixed by adding @Enumerated(EnumType.STRING) to the field in entity.

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

   Like      Discuss      Correct / Improve     hibernate   hibernate criteria   enumerations


 Q46. What is your choice while writing queries within Hibernate - criteria or HQL ?Hibernate
Admin
info@buggybread.com
Ans. I prefer using Criteria for Dynamic queries and HQL for static queries.

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

   Like      Discuss      Correct / Improve     hibernate   hibernate criteria   hql


 Q47. How to specify the or/and combination restrictions within Criteria in Hibernate ? Hibernate2016-11-28 11:52:25

Ans. session.createCriteria(Employee.class).add( Restrictions.or(Restrictions.like("name", "A%"),Restrictions.like("name", "B%"))).list();

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

   Like      Discuss      Correct / Improve     hibernate  Criteria  Restrictions


 Q48. Difference between JDBC and Hibernate ?Database2016-12-06 09:57:14

Ans. JDBC is a standard Java Api for Database communication whereas Hibernate is an ORM framework that uses JDBC to connect with Database.

Hibernate is another layer of object table mapping over JDBC that provide a database independent, object oriented and an efficient way of database communication.

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

   Like      Discuss      Correct / Improve     JDBC  Hibernate  JDBC vs Hibernate     CapTech  Oracle Argentina


 Q49. Can we have an entity in hibernate without primary Key ?Hibernate2016-12-22 14:18:19

Ans. No, Every entity in hibernate needs to have a key, either primary or composite.

If we dont have a primary key on table, there are various ways this problem can be countered.

1. By using composite key on entity ( make sure that the appropriate unique constraint in defined on columns in Database )

2. By mapping Id in entity to ROWID of table.

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

   Like      Discuss      Correct / Improve     hibernate entity  hibernate



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q50. How are DB transactions handled in Hibernate ? Hibernate2017-01-17 13:42:11

 This question was recently asked at 'FINRA'.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          FINRA


 Q51. What are the points to be considered if we move from Eager initialization to Lazy Initialization in Hibernate ?Hibernate2017-01-20 16:00:11

Ans. Make sure that the properties of dependent Hibernate entities are not accessed and if yes, better wrap the whole code within single transaction.

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

   Like      Discuss      Correct / Improve     lazy loading  lazy initialization


 Q52. How does Lazy Initialization helps improving performance of an application ?Hibernate2017-01-20 16:18:52

Ans. Lazy Initialization means , Load Dependencies when required. Which means less load on application resources as only required data is loaded upfront. It's not only good for better performance but for better resource utilization too.

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

   Like      Discuss      Correct / Improve     lazy loading  lazy initialization        frequent


 Q53. Difference between save and flush in Hibernate ?Hibernate2017-01-30 16:00:41

Ans. Save is used to save the entity to the session whereas flush is to save the session content to DB.

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

   Like      Discuss      Correct / Improve     


 Q54. What is a fetch mode in Hibernate ?Hibernate2017-01-30 16:35:55

Ans. It specifies an association fetching strategy. It could be DEFAULT, JOIN or SELECT as following

@Fetch(FetchMode.SELECT)

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

   Like      Discuss      Correct / Improve     


 Q55. What are the methods to connect to database in Java ?Database2017-02-05 09:00:41

Ans. JDBC ( Java Database Connectivity ),ODBC (Open Database Connectivity), Hibernate, JPA ( Java Persistence API ), JOOQ,MyBatis

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

   Like      Discuss      Correct / Improve     database connection  jdbc  ORM  Hibernate     Amdocs


 Q56. Can we have 2 entity fields mapped to the same column in Hibernate ?Hibernate2017-02-16 11:17:51

Ans. No, it's not legal in hibernate. 1 column should be mapped to only one field in entity.

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

   Like      Discuss      Correct / Improve     


 Q57. If we would like to load just the mapping id for the mapped entity, how can we accomplish that.

For example -

Employee entity is mapped to department entity through department id. We want that when we load employee.getDepartment().getDepartmentId(), it shouldn't load the complete department object but just the Id.
Hibernate2017-02-16 11:21:29

Ans. We can use

@AccessType("property") for getDepartmentId() method within Department class in that case.

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

   Like      Discuss      Correct / Improve     


 Q58. If we would like to load just the mapping id for the mapped entity in some cases and whole entity in some cases, because we would like to lazily initialize the dependent entity in some case and not load the entity at all in some case, how can we accomplish that.

For example -

Employee entity is mapped to department entity through department id. We want that when we load employee.getDepartment().getDepartmentId(), it shouldn't load the complete department object but just the Id.
Hibernate2017-02-16 11:24:35

Ans. a

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

   Like      Discuss      Correct / Improve     


 Q59. What does the following exception means

org.hibernate.LazyInitializationException: could not initialize proxy - no Session
Hibernate2017-02-16 11:28:15

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



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q60. 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
Hibernate2017-02-16 13:32:41

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


 Q61. Do you like Native SQL Apis like JDBC or JPA / Hibernate ?Hibernate2017-02-16 20:31:16

 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


 Q62. What are the disadvantages of Hibernate over native APIs ?Hibernate2017-02-16 20:31:40

 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     


 Q63. What was the worst problem you faced while working with Hibernate ?Hibernate2017-02-16 20:32:39

 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     


 Q64. Is it advisable to keep session or transaction open for long time just to avoid LazyInitializationException ?Hibernate2017-02-16 20:33:52

 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     LazyInitializationException  Lazy Loading


 Q65. Does Hibernate synchronize entity with the database automatically i.e any change to entity gets updated in DB ?Hibernate2017-03-09 09:17:46

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 ?Hibernate2017-03-09 09:19:34

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 ?Hibernate2017-03-09 09:20:44

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() ?Hibernate2017-03-09 09:22:22

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()?Hibernate2017-03-09 09:22:58

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



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q70. What are the core interfaces in Hibernate?Hibernate2017-03-09 11:37:41

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     ADP        frequent

Try 1 Question(s) Test


 Q71. What is ConstraintViolationException in Hibernate ?Hibernate2017-03-22 13:13:33

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 ?
Hibernate2017-03-29 12:44:00

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 ?Database2017-06-18 17:52:39

 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     Oracle Argentina


 Q74. Explain Hibernate Validation ?Hibernate2017-08-17 19:30:47

 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


 Q75. What is Lazy Initialization in Hibernate ?Hibernate
a. Feature to load the dependencies from Cache
b. Feature to load all objects and relationships in advance before they can be used
c. Feature to not load dependencies and relationship in advance and load when required
d. Feature to not load the dependencies and relationships at all

Ans.c. Feature to not load dependencies and relationship in advance and load when required

 Q76. Which of the following is not the benefit of Lazy Initialization in Hibernate ?Hibernate
a. Laod When required provides better performance
b. Object stays lighter
c. Less number of Database calls
d. Less load on Database

Ans.c. Less number of Database calls

 Q77. Which of the following is not true for Hibernate Cache ?Hibernate
a. First level cache is enabled by default
b. First level Cache is Session specific
c. First level cache is considered global
d. First level Cache came with Hibernate 1.0

Ans.c. First level cache is considered global

 Q78. Which of the following is not an Hibernate AnnotationHibernate
a. @Id
b. @JoinTable
c. @ManyToMany
d. @Autowired

Ans.d. @Autowired

 Q79. Which of the following Design pattern has been used with Hibernate Criteria ?Hibernate
a. Filter
b. Prototype
c. Builder
d. Observer

Ans.a. Filter

 Q80. Which of following is not core interface of Hibernate ?Hibernate
a. Session
b. Transaction
c. SessionFactory
d. TransactionFactory

Ans.d. TransactionFactory

 Q81. Which of the following session method is used to disassociate / disconnect all objects from the sessionHibernate
a. Clear
b. Evict
c. Close
d. Merge

Ans.a. Clear

 Q82. Which of the following session method is used to disassociate / disconnect a particular object / entity from the sessionHibernate
a. Clear
b. Evict
c. Close
d. Merge

Ans.b. Evict

 Q83. Which of following is not the resolution for preventing LazyInitializationException?Hibernate
a. Set fetch=FetchType.EAGER for Dependent entity mapping
b. Make sure that we are accessing the dependent objects before closing the session
c. Make sure that we are accessing the dependent objects after closing the session
d. Wrap the complete access within Transaction

Ans.c. Make sure that we are accessing the dependent objects after closing the session



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

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:
         

X Close this

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: