ManyToMany org.hibernate.hql.internal.ast.QuerySyntaxException “not mapped”
I'am designing an application with: Eclipse, Jsf, Hibernate, WildFly, Primefaces.
And I'm having the "not Mapped" hibernate problem, and yes, I know we should use Entity names insteat of Table names.
I'm new in here and not sure to how do things properly.
The automaticaly created table is aluno_turma, try as I may, couldn't do nothing with this table.
I looked every answer of all questions about "not mapped", and tried all, but couldn't made it work.
Thanks for any help.
The codes are as follow:
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;
}
Errors
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)
hibernate
add a comment |
I'am designing an application with: Eclipse, Jsf, Hibernate, WildFly, Primefaces.
And I'm having the "not Mapped" hibernate problem, and yes, I know we should use Entity names insteat of Table names.
I'm new in here and not sure to how do things properly.
The automaticaly created table is aluno_turma, try as I may, couldn't do nothing with this table.
I looked every answer of all questions about "not mapped", and tried all, but couldn't made it work.
Thanks for any help.
The codes are as follow:
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;
}
Errors
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)
hibernate
add a comment |
I'am designing an application with: Eclipse, Jsf, Hibernate, WildFly, Primefaces.
And I'm having the "not Mapped" hibernate problem, and yes, I know we should use Entity names insteat of Table names.
I'm new in here and not sure to how do things properly.
The automaticaly created table is aluno_turma, try as I may, couldn't do nothing with this table.
I looked every answer of all questions about "not mapped", and tried all, but couldn't made it work.
Thanks for any help.
The codes are as follow:
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;
}
Errors
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)
hibernate
I'am designing an application with: Eclipse, Jsf, Hibernate, WildFly, Primefaces.
And I'm having the "not Mapped" hibernate problem, and yes, I know we should use Entity names insteat of Table names.
I'm new in here and not sure to how do things properly.
The automaticaly created table is aluno_turma, try as I may, couldn't do nothing with this table.
I looked every answer of all questions about "not mapped", and tried all, but couldn't made it work.
Thanks for any help.
The codes are as follow:
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;
}
Errors
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)
hibernate
hibernate
edited Oct 23 '16 at 7:22


Kukeltje
8,78341338
8,78341338
asked Oct 23 '16 at 3:47
MauricioMauricio
31
31
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You are creating a JPQL query, but using SQL fields. JPQL does use the Object structure for the syntax and not the table structure.
You can try the following:
Query query = em.createQuery("FROM Turma WHERE inativo = false and :aluno MEMBER OF alunos order by nome");
query.setParameter("aluno", aluno);
query.getResultList();
Thank You Very Much !!! (Of about 45 articles I read, not one was like yours)
– Mauricio
Oct 23 '16 at 18:49
Done. Thanks again.
– Mauricio
Oct 25 '16 at 12:19
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40199313%2fmanytomany-org-hibernate-hql-internal-ast-querysyntaxexception-not-mapped%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are creating a JPQL query, but using SQL fields. JPQL does use the Object structure for the syntax and not the table structure.
You can try the following:
Query query = em.createQuery("FROM Turma WHERE inativo = false and :aluno MEMBER OF alunos order by nome");
query.setParameter("aluno", aluno);
query.getResultList();
Thank You Very Much !!! (Of about 45 articles I read, not one was like yours)
– Mauricio
Oct 23 '16 at 18:49
Done. Thanks again.
– Mauricio
Oct 25 '16 at 12:19
add a comment |
You are creating a JPQL query, but using SQL fields. JPQL does use the Object structure for the syntax and not the table structure.
You can try the following:
Query query = em.createQuery("FROM Turma WHERE inativo = false and :aluno MEMBER OF alunos order by nome");
query.setParameter("aluno", aluno);
query.getResultList();
Thank You Very Much !!! (Of about 45 articles I read, not one was like yours)
– Mauricio
Oct 23 '16 at 18:49
Done. Thanks again.
– Mauricio
Oct 25 '16 at 12:19
add a comment |
You are creating a JPQL query, but using SQL fields. JPQL does use the Object structure for the syntax and not the table structure.
You can try the following:
Query query = em.createQuery("FROM Turma WHERE inativo = false and :aluno MEMBER OF alunos order by nome");
query.setParameter("aluno", aluno);
query.getResultList();
You are creating a JPQL query, but using SQL fields. JPQL does use the Object structure for the syntax and not the table structure.
You can try the following:
Query query = em.createQuery("FROM Turma WHERE inativo = false and :aluno MEMBER OF alunos order by nome");
query.setParameter("aluno", aluno);
query.getResultList();
edited Nov 19 '18 at 20:16


Jaumzera
1,1061328
1,1061328
answered Oct 23 '16 at 13:48
mh-devmh-dev
3,18221921
3,18221921
Thank You Very Much !!! (Of about 45 articles I read, not one was like yours)
– Mauricio
Oct 23 '16 at 18:49
Done. Thanks again.
– Mauricio
Oct 25 '16 at 12:19
add a comment |
Thank You Very Much !!! (Of about 45 articles I read, not one was like yours)
– Mauricio
Oct 23 '16 at 18:49
Done. Thanks again.
– Mauricio
Oct 25 '16 at 12:19
Thank You Very Much !!! (Of about 45 articles I read, not one was like yours)
– Mauricio
Oct 23 '16 at 18:49
Thank You Very Much !!! (Of about 45 articles I read, not one was like yours)
– Mauricio
Oct 23 '16 at 18:49
Done. Thanks again.
– Mauricio
Oct 25 '16 at 12:19
Done. Thanks again.
– Mauricio
Oct 25 '16 at 12:19
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40199313%2fmanytomany-org-hibernate-hql-internal-ast-querysyntaxexception-not-mapped%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown