Home Interview Questions and AnswersTechnical Interview Questions and AnswersHibernate Hibernate Interview Questions and Answers For Graduates Part-2

hibernate111.What is Query in hibernate?

Query objects use SQL or Hibernate Query Language (HQL) string to retrieve data from the database and create objects. A Query instance is used to bind query parameters, limit the number of results returned by the query, and finally to execute the query.

12.What is Criteria in hibernate?
Criteria object are used to create and execute object oriented criteria queries to retrieve objects.

13.What are the three states of a persistent entity at a given point in time?
Instances may exist in one of the following three states at a given point in time:

transient: A new instance of a a persistent class which is not associated with a Session and has no representation in the database and no identifier value is considered transient by Hibernate.

persistent: You can make a transient instance persistent by associating it with a Session. A persistent instance has a representation in the database, an identifier value and is associated with a Session.

detached: Once we close the Hibernate Session, the persistent instance will become a detached instance.

14.What is the purpose of Session.beginTransaction() method?
Session.beginTransaction method begins a unit of work and returns the associated Transaction object.

15.Which method is used to add a criteria to a query?
Session.createCriteria creates a new Criteria instance, for the given entity class, or a superclass of an entity class.

16.Which method is used to create a HQL query?
Session.createQuery creates a new instance of Query for the given HQL query string.

17.Which method is used to create a SQL query?
Session.createSQLQuery creates a new instance of SQLQuery for the given SQL query string.

18.Which method is used to remove a persistent instance from the datastore?
Session.delete removes a persistent instance from the datastore.

19.Which method is used to get a persistent instance from the datastore?
Session.get returns the persistent instance of the given named entity with the given identifier, or null if there is no such persistent instance.

20.Which method is used to re-read the state of the given instance from the underlying database?
Session.refresh re-reads the state of the given instance from the underlying database.

 

You may also like

Leave a Comment