storiesnero.blogg.se

Hibernate interview questions
Hibernate interview questions










It can save the changes to the database outside of the transaction. It returns the generated Id after saving the record.ģ. The return type of the save method is java.io.Serializable. Syntax: public Serializable save(Object object) throws HibernateException.Ģ. What is the difference between session save and session persist method in hibernate? Save():ġ. It will not throw any exception in case when no record found.It always hit the database and return the real object, an object that represent the database record not proxy.It will throws ObjectNotFoundException in case when no record found. When we try to retrieve other properties of Employee object, it will hit the database and search the record with employee id 10 and fetch the values. Hibernate will create one fake Employee object in the memory with id 10, but other properties of Employee class will not even be initialized. Example: Let we call session.load(Employee.class,new Integer(10)).If no record found, it will throws an ObjectNotFoundException.In Hibernate, proxy represents a fake object with the given identifier value but its properties are not initialized yet. It will always return a “proxy” in Hibernate terms without hitting the database.What is difference between Hibernate Session get() and load() method? The SessionFactory.openSession() always opens a new session that we have to flush() and close() once we are done with the operations. We can access that session anywhere else by using the SessionFactory.getCurrentSession(). We have to set hibernate.current_session_context_class to thread and then implement something like a servlet filter that opens the session. The SessionFactory.getCurrentSession() returns a session bound to a context. What is difference between openSession and getCurrentSession? See more at: Transaction Management in Hibernate. We have to call beginTransaction()method of Session to start a transaction (Session.beginTransaction()). A transaction is associated with a session. Transaction interface provides the facility to define the units of work or transactions. A transaction has the Atomicity, Consistency, Isolation and Durability properties (ACID). A transaction only completes if all the operations completed successfully. Explain transaction management in hibernate.Ī transaction is a sequence of operation which works as an atomic unit. Is Session a thread-safe object?Ī persistent class object can be in one of the following three states: It acts as a factory for Transaction, Query and Criteria. The session object is created from the SessionFactory object. It maintains the second level cache of the data. It acts as a factory for session objects and client for ConnectionProvider. It is thread-safe object and used by all threads of the application. The SessionFactory object is created from the Configuration object. Mapping information of POJO class properties to database table columns. Mapping information of a POJO class name to a database table name.Ģ. It mainly contains the following mapping information:ġ. Hibernate mapping file is used by hibernate framework to get the information about the mapping of a POJO class and a database table. See more at: Hibernate configuration file. A hibernate configuration file contains all such information. So hibernate needs some configuration setting related to the database and other parameters like mapping files. Hibernate works as an intermediate layer between java application and relational database.

hibernate interview questions

  • Transaction What is hibernate configuration file?.
  • What are the core components are of hibernate architecture? It uses JDBC API for common functionality to communicate with relational database and JNDI and JTA to integrate hibernate to the java application servers. Hibernate architecture consist of hibernate core components and use existing Java APIs. Note: Hibernate framework acts as an intermediate layer between java objects and relational database.

    hibernate interview questions

    It provides the facility to map the java classes to relational database tables and Java data types to SQL data types. It is an open source persistent framework started by Gavin King in 2001. Hibernate framework is an object-relational mapping library for the Java language.












    Hibernate interview questions