Domanda

Quando eseguo

@Nigliedquery (Nome="GroupShasStudent.FindbygroupsidGroups", query="Seleziona G da GroupShasStudent G Dove G.GroupStudentPk.GroupsidGroupsStudentpk.groupsidGroups=: GruppiIdGroups"),

di GroupShasStudent entità, il risultato è generato corretto.Ma un'altra nationalquery

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();
.

Getta l'eccezione

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

In realtà non ho tali tabella in DB, ma il nome corretto è * Gruppi_Has_Student * che è specificato 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() {
    }
.

E anche quando rinominando la tabella in MySQL a GroupShasStudent c'è un'altra eccezione

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

і це сумно ..

È stato utile?

Soluzione

Non è una query nativa (SQL), è una query JPQL, quindi è necessario utilizzare createQuery() anziché createNativeQuery().

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top