The difference between hibernate4 and Hibernate3

Source: Internet
Author: User


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.











Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.