两个不同实体中的相同@NamedQueries 发出警告
Same @NamedQueries in two different entities gives warning
我在两个实体中有相同的 @NamedQueries
,如下所示:
@Table(name = "STUDENT_TABLE")
@NamedQueries({
@NamedQuery(name = "getStudentById", query = "SELECT s FROM Student s where s.stdId=:stdId"),
@NamedQuery(name = "getStudentByName", query = "SELECT s FROM Student s where s.fName=:fName and s.lName =:lName")
})
@Table(name = "MARKS_TABLE")
@NamedQueries({
@NamedQuery(name = "getStudentById", query = "SELECT s FROM Student s where s.stdId=:stdId"),
@NamedQuery(name = "getStudentByName", query = "SELECT s FROM Student s where s.fName=:fName and s.lName =:lName")
})
当我在处理上述内容时,我收到如下警告:
openjpa.MetaData: Warn: Ignoring duplicate query "getStudentById" in "class Student". A query with the same name been already declared in "class Marks".
openjpa.MetaData: Warn: Ignoring duplicate query "getStudentByName" in "class Student". A query with the same name been already declared in "class Marks".
这是什么原因以及我们如何摆脱这个警告?
@NamedQuery
的范围是整个持久化单元。
在不同的实体上定义它们并不重要。
很可能当您定义重复的名称时,其中一个名称将在持久性单元的构建过程中被覆盖。
好的做法是在命名查询前加上实体名称:
@NamedQuery(name = "Student.getStudentById"..
@NamedQuery(name = "Marks.getStudentById"...
我在两个实体中有相同的 @NamedQueries
,如下所示:
@Table(name = "STUDENT_TABLE")
@NamedQueries({
@NamedQuery(name = "getStudentById", query = "SELECT s FROM Student s where s.stdId=:stdId"),
@NamedQuery(name = "getStudentByName", query = "SELECT s FROM Student s where s.fName=:fName and s.lName =:lName")
})
@Table(name = "MARKS_TABLE")
@NamedQueries({
@NamedQuery(name = "getStudentById", query = "SELECT s FROM Student s where s.stdId=:stdId"),
@NamedQuery(name = "getStudentByName", query = "SELECT s FROM Student s where s.fName=:fName and s.lName =:lName")
})
当我在处理上述内容时,我收到如下警告:
openjpa.MetaData: Warn: Ignoring duplicate query "getStudentById" in "class Student". A query with the same name been already declared in "class Marks".
openjpa.MetaData: Warn: Ignoring duplicate query "getStudentByName" in "class Student". A query with the same name been already declared in "class Marks".
这是什么原因以及我们如何摆脱这个警告?
@NamedQuery
的范围是整个持久化单元。
在不同的实体上定义它们并不重要。
很可能当您定义重复的名称时,其中一个名称将在持久性单元的构建过程中被覆盖。
好的做法是在命名查询前加上实体名称:
@NamedQuery(name = "Student.getStudentById"..
@NamedQuery(name = "Marks.getStudentById"...