JPA: caching queries

前端 未结 6 1591
心在旅途
心在旅途 2021-02-07 08:13

I\'m using JPA to load and persist entities in my Java EE-based web application. Hibernate is used as an implementation of JPA, but I don\'t use Hibernate-specific features and

6条回答
  •  遇见更好的自我
    2021-02-07 09:13

    What you want is a NamedQuery. On your Order entity you put:

    @NamedQueries({
        @NamedQuery( name = "getOrderByCustomerId", query = "SELECT o FROM Order o WHERE o.customerId = :customerId")
    })
    

    Then in your DAO use em.createNamedQuery("getOrderByCustomerId") instead of recreating the query.

提交回复
热议问题