0
我正在用Eclipse,Jsf,Hibernate,WildFly,Primefaces設計應用程序。ManyToMany org.hibernate.hql.internal.ast.QuerySyntaxException「not mapped」
而我有「未映射」休眠問題,是的,我知道我們應該使用實體名稱insteat表名稱。 我是新來的,不確定如何做正確的事情。
automaticaly創建的表是aluno_turma,盡我所能嘗試,對此表無能爲力。
我看了關於「未映射」的所有問題的所有答案,並嘗試了所有,但無法使其工作。
感謝您的任何幫助。
的代碼如下:
Aluno.java
@Entity
@ManagedBean
@Table(name = "Aluno")
public class Aluno implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id;
...
@ManyToMany
@JoinTable(name="aluno_turma",
joinColumns={ @JoinColumn(name="aluno_id")},
inverseJoinColumns={ @JoinColumn(name="turma_id")})
private List<Turma> turmas = new ArrayList<Turma>();
...
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
Turma.java
@Entity
@ManagedBean
public class Turma implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id;
private String nome;
private Integer diaSemana;
private String hora;
private String observacao;
private Boolean inativo;
@ManyToOne
private Modalidade modalidade;
@ManyToMany
@JoinTable(name="aluno_turma",
joinColumns={ @JoinColumn(name="turma_id")},
inverseJoinColumns={ @JoinColumn(name="aluno_id")})
private List<Aluno> alunos = new ArrayList<Aluno>();
...
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
alunoMBean.java
@ManagedBean(name="alunoBean")
@SessionScoped
public class AlunoMBean implements Serializable {
...
private List<Turma> turmas;
...
public List<Turma> getTurmas() {
if(this.aluno.getNome() == null) {
List<Turma> listTurma = new ArrayList<Turma>();
return listTurma;
}
if(this.turmas == null) { //Só busca na tabela a primeira vez da consulta
this.turmas = alunoDao.getTurmas(aluno, flagTurma);
}
return this.turmas;
}
alunoDao.java
public List<Turma> getTurmas(Aluno aluno, Boolean flag) {
List<Turma> turmas = new ArrayList<Turma>();
turmas = em.createQuery("from Turma where inativo = 0 and id in (select turma_id from aluno_turma where aluno_id = "+ aluno.getId()+") order by nome ", Turma.class).getResultList();
//That doens't work: Not Mapped
//turmas = em.createQuery("from Turma order by nome ", Turma.class).getResultList();
//That works
return turmas;
}
錯誤
01:43:16,105 ERROR [org.jboss.as.ejb3.invocation] (default task-14) WFLYEJB0034: EJB Invocation failed on component AlunoDao for method public java.util.List br.com.mvtech.alumni.dao.AlunoDao.getTurmas(br.com.mvtech.alumni.modelo.Aluno,java.lang.Boolean): javax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: aluno_turma is not mapped [from br.com.mvtech.alumni.modelo.Turma where inativo = 0 and id in (select turma_id from Aluno_turma where aluno_id = 2) order by nome ]
at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:187)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:277)
非常感謝你! (我閱讀的約45篇文章,沒有一篇像你的文章) – Mauricio
完成。再次感謝。 – Mauricio