Created
January 23, 2014 06:28
-
-
Save yanhua365/8573865 to your computer and use it in GitHub Desktop.
Spring Data JPA 或 JPA Named Query里用注解声明Query Hint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
@NamedQuery(name="findProfessorNoCache", | |
query="SELECT e FROM Professor e WHERE e.id = ?1", | |
hints={@QueryHint(name="toplink.cache-usage", value="DoNotCheckCache")}) | |
public class Professor { | |
@Id | |
private int id; | |
private String name; | |
private long salary; | |
//........... | |
} | |
//http://www.java2s.com/Code/Java/JPA/QueryHintsExample.htm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* To apply JPA QueryHints to the queries declared in your repository interface you can use the QueryHints annotation. | |
* It takes an array of JPA QueryHint annotations plus a boolean flag to potentially disable the hints applied to | |
* the addtional count query triggered when applying pagination. | |
*/ | |
public interface UserRepository extends Repository<User, Long> { | |
@QueryHints(value = { @QueryHint(name = "name", value = "value")}, | |
forCounting = false) | |
Page<User> findByLastname(String lastname, Pageable pageable); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment