标签:framework zab ted connect after creat nat stat database
Hibernate is an open-source and lightweight ORM tool that is used to store, manipulate and retrieve data from the database.
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.
Hibernate architecture comprises of many interfaces such as Configuration, SessionFactory, Session, Transaction etc.
The core interfaces of Hibernate framework are:
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.
Yes, SessionFactory is a thread-safe object, many threads cannot access it simultaneously.
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.
No, Session is not a thread-safe object, many threads can access it simultaneously. In other words, you can share it between threads.
No. | save() | persist() |
---|---|---|
1) | returns the identifier (Serializable) of the instance. | return nothing because its return type is void. |
2) | Syn: public Serializable save(Object o) | Syn: public void persist(Object o) |
The differences between get() and load() methods are given below.
No. | get() | load() |
---|---|---|
1) | Returns null if object is not found. | Throws ObjectNotFoundException if object is not found. |
2) | get() method always hit the database. | load() method doesn‘t hit the database. |
3) | It returns real object not proxy. | It returns proxy object. |
4) | It should be used if you are not sure about the existence of instance. | It should be used if you are sure that instance exists. |
The differences between update() and merge() methods are given below.
No. | update() method | merge() method |
---|---|---|
1) | Update means to edit something. | Merge means to combine something. |
2) | 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. |
Let‘s try to understand the difference by the example given below:
After closing session1, e1 is in detached state. It will not be in session1 cache. So if you call update() method, it will throw an error.
Then, we opened another session and loaded the same Employee instance. If we call merge in session2, changes of e1 will be merged in e2.
There are 3 states of object (instance) in hibernate.
There are 3 ways of inheritance mapping in hibernate.
If you mark a class as mutable="false", class will be treated as an immutable class. By default, it is mutable="true".
The automatic dirty checking feature of hibernate, calls update statement automatically on the objects that are modified in a transaction.
Let‘s understand it by the example given below:
Here, after getting employee instance e1 and we are changing the state of e1.
After changing the state, we are committing the transaction. In such case, state will be updated automatically. This is known as dirty checking in hibernate.
There can be 4 types of association mapping in hibernate.
No, collection mapping can only be performed with One-to-Many and Many-to-Many
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.
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:
No. | First Level Cache | Second Level Cache |
---|---|---|
1) | First Level Cache is associated with Session. | Second Level Cache is associated with SessionFactory. |
2) | It is enabled by default. | It is not enabled by default. |
标签:framework zab ted connect after creat nat stat database
原文地址:https://www.cnblogs.com/vicky-project/p/9191683.html