• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/17

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

17 Cards in this Set

  • Front
  • Back

What is hibernate?


 

Hibernate is an open-source and lightweight ORM tool that is used to store, manipulate and retrieve data from the database.

What is ORM?

ORM is an acronym for Object/Relational mapping. It is a programming strategy to map object with the data stored in the database. It simplifies data creation, data manipulation and data access.

What are the core interfaces of Hibernate?

The core interfaces of Hibernate framework are:

* Configuration
* SessionFactory
* Session
* Query
* Criteria
* Transaction

What is SessionFactory?

SessionFactory provides the instance of Session. It is a factory of Session. It holds the data of second level cache that is not enabled by default.

Is SessionFactory a thread-safe object?

Yes, SessionFactory is a thread-safe object, many threads can access it simultaneously.

What is Session?

It maintains a connection between hibernate application and database.


It provides methods to store, update, delete or fetch data from the database such as persist(), update(), delete(), load(), get() etc.


It is a factory of Query, Criteria and Transaction i.e. it provides factory methods to return these instances.

Is Session a thread-safe object?

No, Session is not a thread-safe object, many threads can't access it simultaneously. In other words, you cannot share it between threads.

What is the difference between session.save() and session.persist() method?

save()


1)returns the identifier (Serializable) of the instance.


2)Syn: public Serializable save(Object o)


persist()


1)return nothing because its return type is void


2)Syn: public void persist(Object o)

What is the difference between get and load method?

get()


Returns null if object is not found;get() method always hit the database; It returns real object not proxy; It should be used if you are not sure about the existence of instance.


load()


Throws ObjectNotFoundException if object is not found;load() method doesn't hit the database;It returns proxy object; It should be used if you are sure that instance exists.


 


 


 


 

What is the difference between update and merge method?

update() should be used if session doesn't contain an already persistent state with same id. It means update should be used inside the session only. After closing the session it will throw error.


merge() should be used if you don't know the state of the session, means you want to make modification at any time.

What are the states of object in hibernate?

1. Transient: The object is in transient state if it is just created but has no primary key (identifier) and not associated with session.
2. Persistent: The object is in persistent state if session is open, and you just saved the instance in the database or retrieved the instance from the database.
3. Detached: The object is in detached state if session is closed. After detached state, object comes to persistent state if you call lock() or update() method.

What are the inheritance mapping strategies?

There are 3 ways of inheritance mapping in hibernate.

1. Table per hierarchy
2. Table per concrete class
3. Table per subclass

How to make a immutable class in hibernate?

If you mark a class as mutable="false", class will be treated as an immutable class. By default, it is mutable="true".

Is it possible to perform collection mapping with One-to-One and Many-to-One?

No, collection mapping can only be performed with One-to-Many and Many-to-Many

What is lazy loading in hibernate?

Lazy loading in hibernate improves the performance. It loads the child objects on demand.


Since Hibernate 3, lazy loading is enabled by default, you don't need to do lazy="true". It means not to load the child objects when parent is loaded.

What is HQL (Hibernate Query Language)?

Hibernate Query Language is known as an object oriented query language. It is like structured query language (SQL).


The main advantage of HQL over SQL is:

1. You don't need to learn SQL
2. Database independent
3. Simple to write query

What is the difference between first level cache and second level cache?

First Level Cache


1)First Level Cache is associated with Session.


2)It is enabled by default.


Second Level Cache


1)Second Level Cache is associated with SessionFactory.


2)It is not enabled by default.