Hibernate cache strategy
Level cache: session, hibernate cache autonomy
2 cache (Ehcache)
Read-write (key issues)
Transactional (transactional cache <Ehcache This mode is not supported >)
JbossCache have 2 cache, and it supports the transactional cache, but very difficult to get information on Jboss, or open-source Ehcache of my tastes, and he, as the default hibernate caching strategy, the performance is also very good J
Spring + hibernate at Ehcache applications are very simple, as long as the statement Ehcache the Cache Manager, and the definition of the xml file ehcache it.
Hibernate lock strategy
Hibernate internal locking mechanism
LockMode.NONE without locking mechanism
LockMode.WRITE hibernate to save and update automatically when the use of the lock mechanism.
Read LockMode.READ hibernate record mechanism
Deal with the entire data process, data is locked
State . Pessimistic locking implementation often depend on the database lock mechanism provided
Mechanisms for implementation are as follows:
Why optimistic locking?
More relaxed locking mechanisms, pessimistic lock on the long transaction, the cost often can not afford; avoid deadlock.
Main Introduction Version
Official recommend implementation of optimistic locking strategy, widely used, can draw on experience of
Implementation, for example: at every time out to read the version number in operation during refresh to update the version number at the same time, updates can only update the version of data low, thereby locking strategy to achieve. Hibernate Session will be waiting for user interaction at the time, Session disconnected database connection. Services at the entire application process, Hibernate Example use of a single Session and a single category to achieve Example.
<class name="mtn.gfkd.spring.model.TUser" table="T_USER" schema="SPRINGDEV" optimistic-lock="version">
column = "version"
name = "version"
type = "java.lang.Integer"
At the same time increase the field of database table àversion
Summary: At the general affairs, it can lock mechanism will not set aside, so that it can not be denied an increase of complexity, you have to face a lot of abnormal version information, and only in relation to key business such as payment for online shopping such as the need for locking on the management, of course, recommend the optimistic locking based on version management.
Hibernate data load
Session.createQuery. Iterate () à traversal , sql statement execution 1,1,1 him so why should we choose?
Session.get / Load
What is the difference?
Session cache / 1, secondary cache
Hibernate batch data processing
The primary problem is the volume after the operation cache problem!
Bulk delete example:
Query query = session.createQuery (delete TUser)
Int ret = query.executeUpdate ();
JDBC interface through efficient batch data delete, Session of the cache, secondary cache has not cleared! !
At this point the session.load (TUser, 1) have data, a clear need for manual handling.
The rules a little
One-many configuration, inverse property will be many of the settings are always set up mainly of the prosecution side (inverse = false)
To distinguish the difference between cascade with the inverse
Even the relationship between class Cascade à
Maintaining control of the direction of the relationship between Inverse à
n there is no instrument can restrict us to restrict the U.S. alone are more than our own imagination.
The above is one of my lectures ppt by hibernate organize, it is inevitable that some unclear, since there is time to slowly filled the J