JPA는 DB에서 테이블을 보이지 않습니다
-
07-09-2020 - |
문제
를 실행할 때
@mencedquery (name="groupshasstudent.findbygroupsidgroups", query="groupShasStudent g에서 g.groupShasStudentPK.GroupSidgroups= : groupsidgroups")에서 선택하십시오.
groupShasStudent 엔티티의엔티티가 올바르게 생성됩니다.하지만 또 다른 quativequery
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에서 테이블이 없지만 올바른 이름은 @table에 지정된 * groups_has_student *입니다.
(내 엔티티 :)
@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'
.
і це сумно ..
해결책
Native (SQL) 쿼리가 아니므로 JPQL 쿼리이므로 createQuery()
대신 createNativeQuery()
를 사용해야합니다.
제휴하지 않습니다 StackOverflow