[英]jpa doesn't see table in db
When I execute 当我执行
@NamedQuery(name = "GroupsHasStudent.findByGroupsidGroups", query = "SELECT g FROM GroupsHasStudent g WHERE g.groupsHasStudentPK.groupsidGroups = :groupsidGroups"), @NamedQuery(name =“ GroupsHasStudent.findByGroupsidGroups”,query =“ SELECT g FROM GroupsHasStudent g WHERE g.groupsHasStudentPK.groupsidGroups =:groupsidGroups”),
of GroupsHasStudent entity, the result is generated correct. 的GroupsHasStudent实体,结果生成正确。 But another NativeQuery 但是另一个NativeQuery
getEntityManager().
createNativeQuery(
"SELECT d.idDiscipline, d.name, gy.idGroupsYear, gy.year, g.idGroups "
+ "FROM Discipline d, Groupsyear gy, Groups g, GroupsHasStudent ghs "
+ "WHERE ghs.groupsHasStudentPK.groupsidGroups=2").
getResultList();
throws the Exception 引发异常
Internal Exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
Table 'mydb.groupshasstudent' doesn't exist
Actually I do don't have such table in db, but the correct name is *groups_has_student* which is specified in @Table: 实际上,我在db中没有这样的表,但是正确的名称是* groups_has_student *,该名称在@Table中指定:
(My entity:) (我的实体:)
@Entity
@Table(name = "groups_has_student")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "GroupsHasStudent.findAll", query = "SELECT g FROM GroupsHasStudent g"),
@NamedQuery(name = "GroupsHasStudent.findByGroupsidGroups", query = "SELECT g FROM GroupsHasStudent g WHERE g.groupsHasStudentPK.groupsidGroups = :groupsidGroups"),
@NamedQuery(name = "GroupsHasStudent.findByStudentUserslogin", query = "SELECT g FROM GroupsHasStudent g WHERE g.groupsHasStudentPK.studentUserslogin = :studentUserslogin")})
public class GroupsHasStudent implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
protected GroupsHasStudentPK groupsHasStudentPK;
public GroupsHasStudent() {
}
And even when I rename table in mysql to groupshasstudent there is another Exception 即使我将mysql中的表重命名为groupshasstudent,也存在另一个异常
Unknown column 'ghs.groupsHasStudentPK.studentUserslogin' in 'where clause'
І це сумно.. 。цесумно..
这不是本机(SQL)查询,而是JPQL查询,因此您应该使用createQuery()
而不是createNativeQuery()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.