更新时间:2023-02-03 16:23:57
You need a short introduction in JPQL, but I will try to quickly explain some missing parts:
在JPQL查询中,您不不写JOIN
条件(即ON
表达式),而是从实体图开始浏览实体图(在下面以StudentWithGraduate
实体开头):
In a JPQL query you do not write which are the JOIN
conditions (i.e the ON
expresions), and instead you navigate through your Entity Graph, beginning with an entity (below I begin with the StudentWithGraduate
entity):
SELECT p.name, o.graduate FROM StudentWithGraduate o
LEFT JOIN o.student s
LEFT JOIN o.subject p
WHERE s.surname=:name
:name"被称为命名参数,它可以帮助您 SQL注入.为了为其设置一个值,您可以编写以下内容:
The ":name" is called a named parameter, which helps you agains SQL injections. In order to set a value for it, you write the following:
Query query = em.createQuery(aboveQuery);
query.setParameter("name", parameterValue);
//....the rest of parameters + getResultList();