File tree Expand file tree Collapse file tree
java/ru/javawebinar/topjava/repository Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package ru .javawebinar .topjava .repository .datajpa ;
22
3- import org .springframework .data .jpa .repository .EntityGraph ;
4- import org .springframework .data .jpa .repository .JpaRepository ;
5- import org .springframework .data .jpa .repository .Modifying ;
6- import org .springframework .data .jpa .repository .Query ;
3+ import org .springframework .data .jpa .repository .*;
74import org .springframework .data .repository .query .Param ;
85import org .springframework .transaction .annotation .Transactional ;
96import ru .javawebinar .topjava .model .User ;
107
8+ import javax .persistence .QueryHint ;
9+
1110@ Transactional (readOnly = true )
1211public interface CrudUserRepository extends JpaRepository <User , Integer > {
1312 @ Transactional
1413 @ Modifying
1514 @ Query ("DELETE FROM User u WHERE u.id=:id" )
1615 int delete (@ Param ("id" ) int id );
1716
17+ // https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#hql-distinct
18+ @ QueryHints ({
19+ @ QueryHint (name = org .hibernate .jpa .QueryHints .HINT_PASS_DISTINCT_THROUGH , value = "false" )
20+ })
1821 User getByEmail (String email );
1922
20- @ EntityGraph (attributePaths = {"meals" , "roles" })
23+ // https://stackoverflow.com/a/46013654/548473
24+ @ EntityGraph (attributePaths = {"meals" }, type = EntityGraph .EntityGraphType .LOAD )
2125 @ Query ("SELECT u FROM User u WHERE u.id=?1" )
2226 User getWithMeals (int id );
2327}
Original file line number Diff line number Diff line change 11package ru .javawebinar .topjava .repository .jpa ;
22
3+ import org .hibernate .jpa .QueryHints ;
34import org .springframework .dao .support .DataAccessUtils ;
45import org .springframework .stereotype .Repository ;
56import org .springframework .transaction .annotation .Transactional ;
@@ -61,6 +62,7 @@ public boolean delete(int id) {
6162 public User getByEmail (String email ) {
6263 List <User > users = em .createNamedQuery (User .BY_EMAIL , User .class )
6364 .setParameter (1 , email )
65+ .setHint (QueryHints .HINT_PASS_DISTINCT_THROUGH , false )
6466 .getResultList ();
6567 return DataAccessUtils .singleResult (users );
6668 }
Original file line number Diff line number Diff line change @@ -6,4 +6,5 @@ database.init=true
66jdbc.initLocation =classpath:db/initDB.sql
77jpa.showSql =true
88hibernate.format_sql =true
9- hibernate.use_sql_comments =true
9+ # https://hibernate.atlassian.net/browse/HHH-13280
10+ hibernate.use_sql_comments =false
You can’t perform that action at this time.
0 commit comments