Skip to content

Commit

Permalink
Enable User methods caching when enableHibernateCache
Browse files Browse the repository at this point in the history
  • Loading branch information
avdev4j committed Nov 13, 2020
1 parent 62b9dfe commit 83253a1
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import org.hibernate.annotations.BatchSize;
<%_ if (enableHibernateCache) { _%>
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Cache;
import org.hibernate.jpa.QueryHints
<%_ } _%>

/**
Expand Down Expand Up @@ -230,14 +231,18 @@ public class User extends PanacheEntityBase implements Serializable {
<% if (cacheManagerIsAvailable) { %>@CacheResult(cacheName = USERS_BY_LOGIN_CACHE)<% } %>
public static Optional<User> findOneWithAuthoritiesByLogin(String login) {
return find("FROM User u LEFT JOIN FETCH u.authorities WHERE u.login = ?1", login)
// .withHint(QueryHints.HINT_CACHEABLE, "true")
<%_ if (enableHibernateCache) { _%>
.withHint(QueryHints.HINT_CACHEABLE, "true")
<%_ } _%>
.firstResultOptional();
}

<% if (cacheManagerIsAvailable) { %>@CacheResult(cacheName = USERS_BY_EMAIL_CACHE)<% } %>
public static Optional<User> findOneWithAuthoritiesByEmailIgnoreCase(String email) {
return find("FROM User u LEFT JOIN FETCH u.authorities WHERE LOWER(u.login) = LOWER(?1)", email)
// .withHint(QueryHints.HINT_CACHEABLE, "true")
<%_ if (enableHibernateCache) { _%>
.withHint(QueryHints.HINT_CACHEABLE, "true")
<%_ } _%>
.firstResultOptional();
}

Expand Down

0 comments on commit 83253a1

Please sign in to comment.