ManyToMany org.hibernate.hql.internal.ast.QuerySyntaxException “not mapped”












0














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)









share|improve this question





























    0














    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)









    share|improve this question



























      0












      0








      0







      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)









      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 23 '16 at 7:22









      Kukeltje

      8,78341338




      8,78341338










      asked Oct 23 '16 at 3:47









      MauricioMauricio

      31




      31
























          1 Answer
          1






          active

          oldest

          votes


















          0














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





          share|improve this answer























          • 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











          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
          });


          }
          });














          draft saved

          draft discarded


















          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









          0














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





          share|improve this answer























          • 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
















          0














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





          share|improve this answer























          • 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














          0












          0








          0






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





          share|improve this answer














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






          share|improve this answer














          share|improve this answer



          share|improve this answer








          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


















          • 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


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith