JPA没有看到表中分贝
问题描述:
当我执行JPA没有看到表中分贝
@NamedQuery(名称= “GroupsHasStudent.findByGroupsidGroups”,查询= “SELECT克FROM GroupsHasStudent克WHERE g.groupsHasStudentPK.groupsidGroups =:groupsidGroups”),
of 群体有学生实体,结果生成正确。但另一个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();
抛出异常
Internal Exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
Table 'mydb.groupshasstudent' doesn't exist
其实我没有在DB这样的表,但正确的名称是* groups_has_student *这是在@Table规定:
(我的实体:)
@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() {
}
即使我在mysql中重命名表到groupshasstudent有另一种异常
Unknown column 'ghs.groupsHasStudentPK.studentUserslogin' in 'where clause'
Іцесумно..
答
这不是一个原生(SQL)查询,这是一个JPQL查询,因此,你应该使用createQuery()
而不是createNativeQuery()
。