anesi.info Lifestyle HIBERNATE INTERVIEW QUESTIONS AND ANSWERS FOR FRESHERS PDF

Hibernate interview questions and answers for freshers pdf

Sunday, March 31, 2019 admin Comments(0)

+ Hibernate Interview Questions and Answers, Question1: What's Hibernate? Question2: What is ORM? Question3: What's the usage of Configuration. These interview questions and answers on Hibernate will help you strengthen your technical skills, PDF was generated at Saturday 10th January, Then check out our detailed Hibernate Interview Questions! Besides studying them online you may download the eBook in PDF format!.


Author: BONNIE ANNESS
Language: English, Spanish, Japanese
Country: Switzerland
Genre: Fiction & Literature
Pages: 663
Published (Last): 31.05.2016
ISBN: 570-3-32410-991-7
ePub File Size: 17.31 MB
PDF File Size: 13.21 MB
Distribution: Free* [*Regsitration Required]
Downloads: 27952
Uploaded by: CECILY

Hibernate is a popular framework of Java which allows an efficient Top 50 Hibernate Interview Questions & Answers .. Download PDF. Dear readers, these Hibernate Interview Questions have been designed specially to get you acquainted with they continue based on further discussion and what you answer: What is .. If you are fresher then interviewer does not expect you. Hibernate is an ORM (object-relational mapping) tool for Java programming language. Download Hibernate Interview Questions PDF.

Hibernate is open source ORM tool. It has a requirement which should be strictly followed in the applications which is a no-argument constructor. Higher level locking or versioning protocol is required to support them. This check has to be added by the developer. Explain how to configure Hibernate. What are the important tags of hibernate. What is HQL?

For questions and freshers pdf answers hibernate interview

Hibernate reduces the time to perform database operations. Hibernate has advantages over using entity beans or JDBC calls. The implementation is done by just using POJOs Read answer 4. What are the main advantages of ORM like hibernate? Read answer 5. What are the core interfaces of Hibernate framework? Session Interface: The basic interface for all hibernate applications. The instances are light weighted and can be created and destroyed without expensive process Read answer 6. Explain how to configure Hibernate.

Hibernate uses a file by name hibernate. This file creates the connection pool and establishes the required environment. A file named. Read answer 7. Define HibernateTemplate.

HibernateTemplate is a helper class that is used to simplify the data access code. This class supports automatically converts HibernateExceptions which is a checked exception into Read answer 8. What are the benefits of HibernateTemplate? HibernateTemplate, which is a Spring Template class, can simplify the interactions with Hibernate Sessions Read answer 9.

What is Hibernate proxy? Mapping of classes can be made into a proxy instead of a table. A proxy is returned when actually a load is called on a session Read answer Explain the types of Hibernate instance states. These states are defined with a persistence context. The Hibernate has the following instance states Explain the Collection types in Hibernate.

A collection is defined as a one-to-many reference. The simplest collection type in Hibernate is What is lazy initialization in hibernate? The delaying the object creation or calculating a value or some process until the first time it is needed. The retrieval of particular information only at the time when the object is accessed What is lazy fetching in hibernate?

Lazy fetching is associated with child objects loading for its parents. What is the difference between sorted and ordered collection in hibernate? Sorted Collection The sorted collection is a collection that is sorted using the Java collections framework.

The sorting is done in the memory of JVM that is running hibernate, soon after reading the data from the database Explain the difference between transient i.

Transient objects do not have association with the databases and session objects. They are simple objects and not persisted to the database Explain the advantages and disadvantages of detached objects. Detached objects passing can be done across layers upto the presentation layer without using Data Transfer Objects Hibernate Query Language is designed for data management using Hibernate technology.

It is completely object oriented and hence has notions like inheritance, polymorphism and abstraction The Hibernate configuration is to be loaded and creation of configuration object is done. The mapping of all hbm files will be performed automatically Explain the role of Session interface in Hibernate. Session interface is a single threaded object. The representation of single unit of work with the Java application and the persistence database is done by this object What is a SessionFactory?

The SessionFactory is the concept that is a single data store and thread safe. Because of this feature, many threads can access this concurrently and the sessions are requested, and also State the role of SessionFactory interface plays in Hibernate. The SessionFactory is used to create Sessions. Each application is having usually only one SessionFactory Read answer Placement practice test: Explain the difference between load and get in Hibernate.

The load method throws an exception,when the unique id could not found in the database What is the difference between merge and update? Write hbm. Whats the difference between load and get?

If you are not sure that the object exists, then use one of the get methods. What is the difference between and merge and update? Use update if you are sure that the session does not contain an already persistent instance with the same identifier, and merge if you want to merge your modifications at any time without consideration of the state of the session.

How do you define sequence generated primary key in hibernate? Define cascade and inverse option in one-many mapping? What do you mean by Named SQL query? Named SQL queries are defined in the mapping xml document and called wherever required. How do you invoke Stored Procedures?

This is a very convenient approach for functionality like "search" screens where there is a www. Define HibernateTemplate? What are the benefits does HibernateTemplate provide? The benefits of HibernateTemplate are: Common functions are simplified to single method calls. Sessions are automatically closed. Exceptions are automatically caught and converted to runtime exceptions.

How do you switch between relational databases without code changes? Hibernate will generate appropriate hql queries based on the dialect defined. If you want to see the Hibernate generated SQL statements on console, what should we do? In Hibernate configuration file set as follows: What are derived properties? The properties that are not mapped to a column, but calculated at runtime by evaluation of an expression are called derived properties.

The expression can be defined using the formula attribute of the element. What is component mapping in Hibernate? What is the difference between sorted and ordered collection in hibernate? The sorting occurs in the memory of JVM which running Hibernate, after the data being read from database using java comparator.

Order collection is sorting a collection by specifying the order-by clause for sorting this collection when retrieval. If your collection is not large, it will be If your collection is very large, it will be www. What is the advantage of Hibernate over jdbc? Hibernate Vs. Hibernate is flexible and powerful ORM solution to map Java classes to database tables.

Hibernate itself takes care of this mapping using XML files so developer does not need to write code for this. With JDBC, the automatic mapping of Java objects with database tables and vice versa conversion is to be taken care of by the developer manually with lines of code. Hibernate provides transparent persistence and developer does not need to write code explicitly to map database tables tuples to application objects during interaction with RDBMS.

Developer has to find out the efficient way to access database, i. Hibernate provides a powerful query language Hibernate Query Language independent from type of database that is expressed in a familiar SQL like syntax and includes full support for polymorphic queries. Hibernate also supports native SQL statements. It also selects an effective way to perform a database manipulation task for an application. Application using JDBC to handle persistent data database tables having database specific code in large amount.

The code written to map table data to application objects and vice versa is actually to map table fields to object properties. Hibernate provides this mapping itself. The actual mapping between tables and application objects is done in XML files. If there is change in Database or in any table then the only need to change XML file properties.

With JDBC, it is developers responsibility to handle JDBC result set and convert it to Java objects through code to use this Hibernate reduces lines of code by maintaining object-table mapping itself and returns result to application in form of Java www. It relieves programmer from manual handling of persistent data, hence reducing the development time and maintenance cost. With JDBC, caching is maintained by hand-coding. Hibernate, with Transparent Persistence, cache is set to application work space.

Relational tuples are moved to this cache as a result of query. It improves performance if client application reads same data many times for same write. Automatic Transparent Persistence allows the developer to concentrate more on business logic rather than this application code.

In JDBC there is no check that always every user has updated data. This check has to be added by the developer. Hibernate enables developer to define version type field to application, due to this defined field Hibernate updates version field of database table every time relational tuple is updated in form of Java class object to that table.

So if two users retrieve same tuple and then modify it and one user save this modified tuple to database, version is automatically updated for this tuple by Hibernate. When other user tries to save updated tuple to database then it does not allow saving it because this user does not have updated data. What are the Collection types in Hibernate? Bag Set List Array Map What are the ways to express joins in HQL? HQL provides four ways of expressing inner and outer joins: What is Hibernate proxy?

The proxy attribute enables lazy initialization of persistent instances of the class. The actual persistent object will be loaded when a method of the proxy is invoked. How can Hibernate be configured to access an instance variable directly and not through a setter method?

This forces hibernate to bypass the setter method and access the instance variable directly while initializing a newly loaded object. How can a whole class be mapped as immutable? This specifies that instances of the class are not mutable. Immutable classes, may not be updated or deleted by the application.

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

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

What are Callback interfaces? Callback interfaces allow the application to receive a notification when something interesting happens to an objectfor 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. What are the types of Hibernate instance states?

Top 50 Hibernate Interview Questions & Answers

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 What are the differences between EJB 3. Bidirectional relationships are implemented by two unidirectional relationships Entity Relationships are bidirectional or unidirectional 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 www. Latest Answer: Read Answers 6 Asked by: In order to call a stored procedure using the hibernate , define a named query for a persistent class mapping document.

Then call the named query from your java application. Example is given in the Hibernate Reference documentation as follows: Read Answers 3 Asked by: These are the few questions that continuously get asked in most of forums. Whats really difference between two and really more importantly when should I use one over the other. Its pretty interesting question because there are major differences To make the application developemnt more productive. Read Answers 2 Asked by: Read Answers 5 Asked by: You can declare it as Named queiries in one of your mapping files and give unique name.

Call it in your code. Sample code is below. Read Answers 4 Asked by: In my opinion in case of Entity Beans our bean only work under contanier. There is no concept of Detached Objects. But in case of hibernate we have detached object concepts. Read Answers 1 Asked by: In other words, Proxies are created dynamically by subclassing your object at runtime.

The subclass has all the methods of the parent, and when any of the methods are accessed, the proxy loads up the real object from the DB and calls the method for you. Very nice in How will you configure Hibernate? The configuration files hibernate.

Session instances are the primary interface for the persistence service.

Interview freshers pdf answers questions hibernate and for

These two files are used to configure the hibernate sevice connection driver class, connection URL, connection username, connection password, dialect etc. If both files are present in the classpath then hibernate. These files are used to map persistent objects to a relational database.

It is the best practice to store each object in an individual mapping file i. The naming convention is to use the same name as the persistent POJO class name. For example Account. What is a SessionFactory? Is it a thread-safe object? SessionFactory is Hibernate s concept of a single datastore and is threadsafe so that many threads can access it concurrently and request for sessions and immutable cache of compiled mappings for a single database. One-to-One Association b.

Many-to-Many Association. In how many ways, objects can be fetched from database in hibernate?

46 Hibernate Interview Questions and Answers - Freshers, Experienced

Hibernate provides following four ways to fetch objects from database: Using HQL b. Using identifier c. Using Criteria API d. Using Standard SQL. How primary key is created by using hibernate? Database primary key is specified in the configuration file hbm. Generator can also be used to specify how primary key is being created in the database. In the below example, deptId acts as primary key:.

Objects which have been detached and are no longer associated with any persistent entities can be reattached by calling session. What are different ways to disable hibernate second level cache? Hibernate second level cache can be disabled using any of the following ways: Using cache provider as org. What is ORM metadata? Which one is the default transaction factory in hibernate?

With hibernate 3. JMX provides tools for development of efficient and robust distributed, web based solutions. How can we bind hibernate session factory to JNDI? Hibernate session factory can be bound to JNDI by making configuration changes in hibernate. In how many ways objects can be identified in Hibernate? Object identification can be done in hibernate in following three ways: Using Object Identity: Using Object Equality: Using equals method.

Using database identity: Relational database objects can be identified if they represent same row. What different fetching strategies are of hibernate?

Following fetching strategies are available in hibernate: Join Fetching 2. Batch Fetching 3. Select Fetching 4. Sub-select Fetching How mapping of java objects is done with database tables? To map java objects with database tables, we need to have Java beans properties names same as column names of a database table. Then mapping is provided in hbm. What are derived properties in hibernate? Derived properties are those properties which are not mapped to any columns of a database table.

Such properties are calculated at runtime by evaluation of any expressions. Named SQL queries are those queries which are defined in mapping file and are called as required anywhere. So, ideally we should use Load method only when we are sure about existence of records against an id.

Version property is used in hibernate to know whether an object is in transient state or in detached state.

Hibernate Interview Questions.pdf

What is attribute oriented programming? In Attribute oriented programming, a developer can add Meta data attributes in the java source code to add more significance in the code.

For Java hibernate , attribute oriented programming is enabled by an engine called XDoclet. Does hibernate support polymorphism? Yes, hibernate fully supports polymorphism. Polymorphism queries and polymorphism associations are supported in all mapping strategies of hibernate.

What the three inheritance models are of hibernate? Hibernate has following three inheritance models: Tables Per Concrete Class b. Table per class hierarchy c.

Hibernate Interview Questions

Table per sub-class. How can we map the classes as immutable? Load configuration file and create object of configuration class. Using configuration object, create sessionFactory object. From sessionFactory, get one session. Create HQL query. Execute HQL query and get the results.

Results will be in the form of a list.