Hibernate depth

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

Pessimistic locking

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:




Optimistic locking

Why optimistic locking?

More relaxed locking mechanisms, pessimistic lock on the long transaction, the cost often can not afford; avoid deadlock.

Implementation mechanisms:




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">

<Primary key>

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.list ()

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

QueryCache mechanism

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

分类:Java 时间:2009-05-12 人气:1078
blog comments powered by Disqus


  • Get a database connection (in the normal way and the way the data source) 2010-12-15

    Step One: Create a JavaWeb works, called DBConnPrjTest (this project name is variable) Step Two: In DBConnPrjTest \ WebRoot \ WEB-INF \ lib, add the following package and loaded into the project: commons-logging-1.1.1.jar ojdbc14.jar: oracle database

  • Daquan various database connection c # 2011-06-01

    C # SQL database connections in China trading network connects to the database of the steps: 1, the establishment of SqlConnection object; 2, the specified SqlConnection object's ConnectionString property; 3, open the database connection; 4, specify

  • tomcat6 database connection pool configuration in detail 2011-09-08

    tomcat6 database connection pool configuration in detail I first explain the configuration of the environment under tomcat version is apache-tomcat-6.0.33 non-installation version, the path is D: \ Java \ apache-tomcat-6.0.33, tomcat does not affect

  • Cache and connection pool to access the database on the performance of 2010-07-02

    Acquaintance cache and connection pool Envisage such a scenario: You suddenly feel thirsty, need a glass of water to ease, speaking from the heart, of course, the sooner the better. Typically, a glass of water production from water (well water, river

  • hibernate configuration data source. hibernate - Database Connection Pool 2009-04-30

    In order to configure their own testing environment, and required their entire framework of the abstract, the introduction of the test framework, the tests have their own test cases. Database connection pool but found the old problems, questions and

  • Transfer: an overview of java database connection specification 3.0 features and improvements new 2010-06-02

    Overview java database connection specification 3.0 new features and improvements josh heidebrecht (jheidebr@ca.ibm.com) Software engineer, ibm July 2001 java database connectivity (java database connectivity, jdbc) api as java 2 Standard Edition (ja

  • Database connection pool c3p0 arguments detailed to support the weight with 2010-04-28

    import java.sql.Connection; import java.sql.SQLException; import com.mchange.v2.c3p0.ComboPooledDataSource; import com.mchange.v2.c3p0.DataSources; public final class ConnectionManager ( private static ConnectionManager instance; private ComboPooledD

  • The basic principles of database connection pool 2010-06-11

    Traditional database connection (refer to the basic realization through DriverManager and DataSource to connect), a database connection objects are corresponding to a physical database connection, database connection and the closure of the establishm

  • Database connection pool configuration Xiangjie (dbcp, c3p0) 2010-07-25

    <bean destroy-method="close"> <property name="driverClassName"><value>${jdbcHospital.driverClassName}</value></property> <property name="url"><value>${jdbcHospital.url}</value>&

  • PHP database connection class - DB Class 2010-08-19

    For PHP applications for more than 90% of the needs and database to deal with. So how do you manipulate the database? When you upgrade or change the back-end database, you can follow these procedures to upgrade and mount it smooth? If you are conside

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 闽ICP备15018612号

processed in 0.033 (s). 13 q(s)