Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yanhua365/8573865 to your computer and use it in GitHub Desktop.
Save yanhua365/8573865 to your computer and use it in GitHub Desktop.
Spring Data JPA 或 JPA Named Query里用注解声明Query Hint
@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
/**
* 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