What is a named query?

后端 未结 6 399
感情败类
感情败类 2020-12-25 11:00

I have read its definition but not able to understand fully.

6条回答
  •  遥遥无期
    2020-12-25 11:46

    According to http://www.objectdb.com/java/jpa/query/named A named query is a statically defined query with a predefined unchangeable query string. Using named queries instead of dynamic queries may improve code organization by separating the JPQL query strings from the Java code. It also enforces the use of query parameters rather than embedding literals dynamically into the query string and results in more efficient queries.

    Here is an Example, You should import

    import javax.persistence.NamedQueries; import javax.persistence.NamedQuery;

    @NamedQueries({
        @NamedQuery(name = "Tenantdata.findAll", query = "SELECT c FROM Tenantdata c"),
        @NamedQuery(name = "Tenantdata.findById", query = "SELECT c FROM Tenantdata c WHERE c.id = :id")
    }    
    )
    

提交回复
热议问题