Summary The differences between Hibernate4.1 + and Hibernate3.3 +

Source: Internet
Author: User

Take advantage of the vacation time to learn about today's popular ORMapping framework-Hibernate,After reading the classic Hibernate video tutorial provided by Jack Ma, you can get started.

The Hibernate version used by instructor Ma In the lecture is 3.3.2, And we download the latest version 4.2.3 from the official Hibernate website.

Of course, the upgrade process of Hibernate from Version 3 + to version 4 + (to adapt to JPA2.0 ?) I used version 4.2.3 for experiments, so I will summarize the differences below. (Welcome to criticize and correct)

1. Use the hibernate. properties configuration file

The following configuration information does not need to be written in the traditional hibernate. cfg. xml file, but can be written in the hibernate. properties configuration file.


2. buildSessionFactory method of the SessionFactory object

In version 4.1 +, buildSessionFactory () without parameters has been abolished and replaced by buildSessionFactory (ServiceRegistry)

Therefore, we adopt the following methods:

   SessionFactory sf  =   = =         sf =  

Note the following two points:

1) if you use an XML configuration file to configure the object class: You must manually add the resource file to the code.

(The configuration in hibernate. cfg. xml is invalid. <mapping resource = "cn/ntt/china/model/Student. hbm. xml"/>)

Example: cfg. addResource ("cn/ntt/china/model/Student. hbm. xml"); // specify the full path

2) If the annotation method is used: add the configuration in hibernate. cfg. xml, just like the original version 3.3 +.

Example: <mapping class = "cn. ntt. china. model. Teacher"/>

Deprecated. All functionality has been movedConfiguration)

The class used to read the configuration of this annotation has been discarded. Currently, the annotation is not required to read the configuration.

To adapt to JPA specifications, we recommend that you use the annotation configuration in Hibernate4.1 +.

Therefore, when a jar package is imported, all the packages in requested will contain the annotation required package.

3. Second-level cache Configuration

3.3 +:

        true        true        org.hibernate.cache.EhCacheProvider

Now 4.1 +:

        true        true        org.hibernate.cache.ehcache.EhCacheRegionFactory

 

Hibernate has learned that it has come to an end. Looking back at this, the core idea of Hibernate is actually to convert the operations on the relationship between tables in the database and tables into operations encapsulated into java objects and objects! So why?

The reason is simple. This is in line with our daily Object-Oriented Programming habits and simplifies code for persistent layer operations.

Sun has developed a set of specifications for this idea, that is, JPA! In the near future, Java persistence operations will be unified by JPA.

Finally, I would like to thank Jack Ma for his wonderful explanation in the video!

 

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.