Reputation: 4190
When I execute
@NamedQuery(name = "GroupsHasStudent.findByGroupsidGroups", query = "SELECT g FROM GroupsHasStudent g WHERE g.groupsHasStudentPK.groupsidGroups = :groupsidGroups"),
of GroupsHasStudent entity, the result is generated correct. But another 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:
(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
Unknown column 'ghs.groupsHasStudentPK.studentUserslogin' in 'where clause'
І це сумно..
Upvotes: 0
Views: 931
Reputation: 242686
It's not a native (SQL) query, it's a JPQL query, therefore you should use createQuery()
instead of createNativeQuery()
.
Upvotes: 1