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 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 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.