Pregunta

Cuando ejecuto

@NamedQuery(name = "GroupsHasStudent.findByGroupsidGroups", query = "SELECT g DE GroupsHasStudent g DONDE g.groupsHasStudentPK.groupsidGroups = :groupsidGroups"),

de GroupsHasStudent entidad, el resultado es generado correcta.Pero otra 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();

lanza la Excepción

Internal Exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
Table 'mydb.groupshasstudent' doesn't exist

Yo en realidad no tienen dicha tabla en la db, pero el nombre correcto es *groups_has_student* que se especifica en @Tabla:

(Mi persona:)

@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() {
    }

E incluso cuando me cambie el nombre de la tabla en mysql groupshasstudent hay otra Excepción

Unknown column 'ghs.groupsHasStudentPK.studentUserslogin' in 'where clause'

Y це сумно..

¿Fue útil?

Solución

No es un nativo (SQL) de la consulta, es una consulta JPQL, por lo tanto, usted debe utilizar createQuery() en lugar de createNativeQuery().

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top