Version upgrade, in fact, the internal is an ORM of the mapping package, the new version has been optimized in the lower version of the enhanced, especially the level two cache, and first-level cache, the level
of cache is session level, the default is saved in Hibernate memory, The second level cache is the sessionfactory level, generally often does not need to
revise the city these we can put in the level two cache to do the preload, does not need the long-term change, but also may reduce the performance consumption, for example
Oscache and so on common two level cache
In the Hibernate4,
Annotationconfiguration has expired.
For the annotation configuration, there is no new class to replace it, but it is implemented by putting this part of the functionality into the configuration class.
Java code
Configuration CFG = new configuration (). Configure ();
The above statement resolves the annotation configuration in hibernate4.
The buildsessionfactory () method expires.
The positive solution for creating sessionfactory is as follows:
Java code
Configuration CFG = new configuration (). Configure ();
Serviceregistry serviceregistry = new Serviceregistrybuilder (). Applysettings (Cfg.getproperties ()). Buildserviceregistry ();
Sessionfactory factory = Cfg.buildsessionfactory (serviceregistry);
Integration with Spring3
Starting with spring3.1, the Hibernate4 hibernatedaosupport and hibernatetemplate are not available, but the native Hibernate4 API is used to get the session.
If you want to configure sessionfactory in Spring3, or manage transactions, the code is as follows:
XML code
<bean id= "Sessionfactory" class= "Org.springframework.orm.hibernate4.LocalSessionFactoryBean" >
...
</ bean> <bean id= "TransactionManager" class= "Org.springframework.orm.hibernate4.HibernateTransactionManager" >
<property name= "sessionfactory" ref= "Sessionfactory"/> </bean>
Note that the package name here is Org.springframework.orm. hibernate4.