"Java EE learning 48th Day" "Hibernate Learning Fifth Day" "Crawl Strategy" "Level Two Cache" "HQL"

Source: Internet
Author: User
Tags jboss

First, crawl strategy.

Three crawl strategies are available in the 1.hibernate.

(1) connection fetching (join FETCH): This is the default way to crawl. Using this crawl mode, Hibernate gets the object's associated object or associated collection in the same way as the connection within select.

(2) Query fetch (SELECT FETCH): This fetching method will send another SELECT statement to fetch the associated entity or collection of the current object. Unless Lazy=false is specified, the second SELECT statement is executed only when the association is actually accessed.

(3) subquery fetch (Subselect fetch): Also send a SELECT statement to fetch the associated collection of all the entity objects previously queried. Unless Lazy=false is specified, the second SELECT statement is executed only when the association is actually accessed.

2. The case, access to all student information for the course number 1 or 2.

The results show that if you use Select or join, the efficiency is the same, the SQL statements are sent exactly the same, and if you use subselect, the efficiency is much higher, only two SQL statements are required.

1  Packagecom.kdyzm.fetchtest;2 3 Importjava.util.List;4 ImportJava.util.Set;5 6 Importorg.hibernate.Session;7 Importorg.hibernate.SessionFactory;8 Importorg.hibernate.cfg.Configuration;9 Importorg.junit.Test;Ten  One ImportCom.kdyzm.hibernate.domain.Course; A Importcom.kdyzm.hibernate.domain.Student; -  -  Public classFetchtest { the     Private Staticsessionfactory sessionfactory; -     Static{ -Configuration configuration=NewConfiguration (); - configuration.configure (); +sessionfactory=configuration.buildsessionfactory (); -     } +     /* A * n+1-bar query is a notable feature.  at      */ - @Test -      Public voidbasetest () { -Session session=sessionfactory.opensession (); -List<student>students=session.createquery ("From Student"). List (); -          for(Student student:students) { inset<course>courses=student.getcourses (); -              for(Course course:courses) { to System.out.println (course); +             } -         } the session.close (); *     } $     Panax Notoginseng     /* - * Query Class CID for all students of 1,3 the      *  + * subselect (Fetch attribute value) is usually used if a subquery is needed A * Only two SQL statements are required to use subselect.  the      *  +      */ - @Test $      Public voidtest2 () { $Session session=sessionfactory.opensession (); -List<course>courses=session.createquery ("from Course where Cid in (1,3)"). List (); -          for(Course course:courses) { theset<student>students=course.getstudents (); -              for(Student student:students) {Wuyi System.out.println (student); the             } -         } Wu session.close (); -     } About      $     /* - * Summary: In the above requirements, using the Select and join method is the same efficiency, using sub-query subselect efficiency is the most efficient.  -      */ -      A      +}
Fetchtest.java

二、二级 Cache

1. The level two cache is not implemented by hibernate and must be implemented with third-party plugins.

2. Level two cache common cache policy providers:

Cache

Provider class

Type

Cluster Safe

Query Cache Supported

Hashtable (not intended for production use)

Org.hibernate.cache.HashtableCacheProvider

Memory

Yes

EHCache

Org.hibernate.cache.EhCacheProvider

Memory,disk

Yes

Oscache

Org.hibernate.cache.OSCacheProvider

Memory,disk

Yes

Swarmcache

Org.hibernate.cache.SwarmCacheProvider

Clustered (IP multicast)

Yes (clustered invalidation)

JBoss Cache 1.x

Org.hibernate.cache.TreeCacheProvider

Clustered (IP multicast), transactional

Yes (replication)

Yes (Clock sync req.)

JBoss Cache 2

Org.hibernate.cache.jbc.JBossCacheRegionFactory

Clustered (IP multicast), transactional

Yes (replication or invalidation)

Yes (Clock sync req.)

  

"Java EE learning 48th Day" "Hibernate Learning Fifth Day" "Crawl Strategy" "Level Two Cache" "HQL"

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.