Vous êtes sur la page 1sur 18

7 Tips to boost your Hibernate performance https://thoughts-on-java.

org/tips-to-boost-your-hibernate-performance/

▼ ▼ ▼ ▼

tweet share share share share email

1 of 18 6/14/2019, 10:34 AM
7 Tips to boost your Hibernate performance https://thoughts-on-java.org/tips-to-boost-your-hibernate-performance/

▼ ▼ ▼ ▼

2 of 18 6/14/2019, 10:34 AM
7 Tips to boost your Hibernate performance https://thoughts-on-java.org/tips-to-boost-your-hibernate-performance/

▼ ▼ ▼ ▼

1 2015-03-03 20:28:52,484 DEBUG [org.hibernate.stat.internal.ConcurrentStatisticsImpl] (


2 2015-03-03 20:28:52,484 INFO [org.hibernate.engine.internal.StatisticalLoggingSessionEventL
3 8728028 nanoseconds spent acquiring 12 JDBC connections;
4 295527 nanoseconds spent releasing 12 JDBC connections;
5 12014439 nanoseconds spent preparing 21 JDBC statements;
6 5622686 nanoseconds spent executing 21 JDBC statements;
7 0 nanoseconds spent executing 0 JDBC batches;
8 0 nanoseconds spent performing 0 L2C puts;
9 0 nanoseconds spent performing 0 L2C hits;
10 0 nanoseconds spent performing 0 L2C misses;
11 403863 nanoseconds spent executing 1 flushes (flushing a total of 10 entities
12 25529864 nanoseconds spent executing 1 partial-flushes (flushing a total
13 }

3 of 18 6/14/2019, 10:34 AM
7 Tips to boost your Hibernate performance https://thoughts-on-java.org/tips-to-boost-your-hibernate-performance/

▼ ▼ ▼ ▼

1 @ManyToMany( mappedBy="authors", fetch=FetchType.LAZY)

1 SELECT DISTINCT a FROM Author a JOIN FETCH a.books b

1 @NamedEntityGraph(name = "graph.AuthorBooksReviews",
2 attributeNodes = @NamedAttributeNode(value = "books"))

4 of 18 6/14/2019, 10:34 AM
7 Tips to boost your Hibernate performance https://thoughts-on-java.org/tips-to-boost-your-hibernate-performance/

▼ ▼ ▼ ▼

1 EntityGraph graph = this.em.createEntityGraph(Author.class);


2 Subgraph<Book> bookSubGraph = graph.addSubgraph(Author_.books);

1 @NamedStoredProcedureQuery(
2 name = "getBooks",
3 procedureName = "get_books",
4 resultClasses = Book.class,
5 parameters = { @StoredProcedureParameter(mode = ParameterMode.REF_CURSOR, type =
6 )

5 of 18 6/14/2019, 10:34 AM
7 Tips to boost your Hibernate performance https://thoughts-on-java.org/tips-to-boost-your-hibernate-performance/

▼ ▼ ▼ ▼

1 CriteriaBuilder cb = this.em.getCriteriaBuilder();

6 of 18 6/14/2019, 10:34 AM
7 Tips to boost your Hibernate performance https://thoughts-on-java.org/tips-to-boost-your-hibernate-performance/

▼ ▼ ▼ ▼

8
9 // set update and where clause
10 update.set("amount", newAmount);
11 update.where(cb.greaterThanOrEqualTo(e.get("amount"), oldAmount));
12
13 // perform update
14 this.em.createQuery(update).executeUpdate();

7 of 18 6/14/2019, 10:34 AM
7 Tips to boost your Hibernate performance https://thoughts-on-java.org/tips-to-boost-your-hibernate-performance/

▼ ▼ ▼ ▼

8 of 18 6/14/2019, 10:34 AM
7 Tips to boost your Hibernate performance https://thoughts-on-java.org/tips-to-boost-your-hibernate-performance/

▼ ▼ ▼ ▼

9 of 18 6/14/2019, 10:34 AM
7 Tips to boost your Hibernate performance https://thoughts-on-java.org/tips-to-boost-your-hibernate-performance/

▼ ▼ ▼ ▼

10 of 18 6/14/2019, 10:34 AM
7 Tips to boost your Hibernate performance https://thoughts-on-java.org/tips-to-boost-your-hibernate-performance/

▼ ▼ ▼ ▼

11 of 18 6/14/2019, 10:34 AM
7 Tips to boost your Hibernate performance https://thoughts-on-java.org/tips-to-boost-your-hibernate-performance/

▼ ▼ ▼ ▼

12 of 18 6/14/2019, 10:34 AM
7 Tips to boost your Hibernate performance https://thoughts-on-java.org/tips-to-boost-your-hibernate-performance/

▼ ▼ ▼ ▼

13 of 18 6/14/2019, 10:34 AM
7 Tips to boost your Hibernate performance https://thoughts-on-java.org/tips-to-boost-your-hibernate-performance/

▼ ▼ ▼ ▼

14 of 18 6/14/2019, 10:34 AM
7 Tips to boost your Hibernate performance https://thoughts-on-java.org/tips-to-boost-your-hibernate-performance/

▼ ▼ ▼ ▼

15 of 18 6/14/2019, 10:34 AM
7 Tips to boost your Hibernate performance https://thoughts-on-java.org/tips-to-boost-your-hibernate-performance/

▼ ▼ ▼ ▼

16 of 18 6/14/2019, 10:34 AM
7 Tips to boost your Hibernate performance https://thoughts-on-java.org/tips-to-boost-your-hibernate-performance/

▼ ▼ ▼ ▼

17 of 18 6/14/2019, 10:34 AM
7 Tips to boost your Hibernate performance https://thoughts-on-java.org/tips-to-boost-your-hibernate-performance/

▼ ▼ ▼ ▼

18 of 18 6/14/2019, 10:34 AM