Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 846479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:37:14+00:00 2026-05-15T06:37:14+00:00

Here my EJB @Entity @Table(name = modelos) @NamedQueries({ @NamedQuery(name = Modelos.findAll, query = SELECT

  • 0

Here my EJB

@Entity
@Table(name = "modelos")
@NamedQueries({
    @NamedQuery(name = "Modelos.findAll", query = "SELECT m FROM Modelos m"),
    @NamedQuery(name = "Modelos.findById", query = "SELECT m FROM Modelos m WHERE m.id = :id"),
    @NamedQuery(name = "Modelos.findByDescripcion", query = "SELECT m FROM Modelos m WHERE m.descripcion = :descripcion")})
public class Modelos implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @Column(name = "descripcion")
    private String descripcion;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idModelo")
    private Collection<Produtos> produtosCollection;
    @JoinColumn(name = "id_marca", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Marcas idMarca;

    public Modelos() {
    }

    public Modelos(Integer id) {
        this.id = id;
    }

    public Modelos(Integer id, String descripcion) {
        this.id = id;
        this.descripcion = descripcion;
    }

    public Modelos(Integer id, Marcas idMarca) {
        this.id = id;
        this.idMarca = idMarca;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
    }

    public Collection<Produtos> getProdutosCollection() {
        return produtosCollection;
    }

    public void setProdutosCollection(Collection<Produtos> produtosCollection) {
        this.produtosCollection = produtosCollection;
    }

    public Marcas getIdMarca() {
        return idMarca;
    }

    public void setIdMarca(Marcas idMarca) {
        this.idMarca = idMarca;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Modelos)) {
            return false;
        }
        Modelos other = (Modelos) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "" + descripcion + "";
    }

}

And the method accesing from the Modelosfacade

public List<Modelos> findByMarcas(Marcas idMarca){
    return em.createQuery("SELECT id, descripcion FROM Modelos WHERE idMarca = "+idMarca.getId()+"").getResultList();
}

And the calling method from the controller

public String createByMarcas() {
    //recreateModel();
    items = new ListDataModel(ejbFacade.findByMarcas(current.getIdMarca()));
    updateCurrentItem();
    System.out.println(current.getIdMarca());
    return "List";
}

I do not understand why I keep falling in an EJB exception.

Caused by: javax.ejb.EJBException
 at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5070)
 at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:4968)
 at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4756)
 at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1955)
 at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1906)
 at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:198)
 at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:84)
 at $Proxy347.findByMarcas(Unknown Source)
 at controladores.__EJB31_Generated__ModelosFacade__Intf____Bean__.findByMarcas(Unknown Source)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:37:14+00:00Added an answer on May 15, 2026 at 6:37 am

    Actually, I’m almost sure that there are more useful traces in the server logs. But anyway, I have some remarks:

    First of all, the id of a Marca is not an attribute of Modelos so your query is not correct, you need to either pass an instance or Marcas or to navigate through the association if you pass the id (you need to think object and associations when using JPA).

    Secondly, the way you are performing your query is not correct, you should parametrize it.

    Thirdly, when using SQL projections, you get an Object[] (or a List<Object[]> if there are multiple results), not a strong typed result unless you use the SELECT NEW constructor expression.

    To summarize, the following should work:

    public List<Object[]> findByMarcas(Marcas marcas){
        Query q = em.createQuery("SELECT m.id, m.descripcion FROM Modelos m WHERE m.idMarca = :marcas");
        q.setParameter("marcas", marcas);
        return q.getResultList();
    }
    

    Or, if you pass the id as the parameter of the query (but the above query is just fine):

    public List<Object[]> findByMarcas(Marcas marcas){
        Query q = em.createQuery("SELECT m.id, m.descripcion FROM Modelos m WHERE m.idMarca.id = :idMarca");
        q.setParameter("idMarca", marcas.getId());
        return q.getResultList();
    }
    

    But I would either not use projections or use a SELECT NEW constructor expression:

    public List<Modelos> findByMarcas(Marcas marcas){
        Query q = em.createQuery("SELECT m FROM Modelos m WHERE m.idMarca.id = :idMarca");
        q.setParameter("idMarca", marcas.getId());
        return q.getResultList();
    }
    

    or (assuming Modelos has an appropriate constructor):

    public List<Modelos> findByMarcas(Marcas marcas){
        Query q = em.createQuery("SELECT NEW com.acme.Modelos(m.id, m.descripcion) FROM Modelos m WHERE m.idMarca.id = :idMarca");
        q.setParameter("idMarca", marcas.getId());
        return q.getResultList();
    }
    

    And actually, I would use a named query, for example:

    @NamedQuery(
        name="Modelos.findByMarcas",
        query="SELECT m FROM Modelos m WHERE m.idMarca = :marcas"
    )
    

    and use:

    public List<Modelos> findByMarcas(Marcas marcas){
        Query q = em.createNamedQuery("Modelos.findByMarcas");
        q.setParameter("marcas", marcas);
        return q.getResultList();
    }
    

    By the way, I would rename idMarca into marcas on the Modelos entity, idMarca is misleading:

    @ManyToOne(optional = false)
    private Marcas marcas;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 486k
  • Answers 486k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You might want to take a look at the source… May 16, 2026 at 7:57 am
  • Editorial Team
    Editorial Team added an answer The second part of your question is easier to address,… May 16, 2026 at 7:57 am
  • Editorial Team
    Editorial Team added an answer OK I solved this by looking at the NSWindowController header… May 16, 2026 at 7:57 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.