NoSuchMethodException on eclipselink - jsf

I'm developing a javaEE project using Glassfish and EclipseLink.
ALthough, when i run my app i get the following exceptions:
Exception [EclipseLink-60] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The method [_persistence_setjuego_vh] or [_persistence_getjuego_vh] is not defined in the object [model.ConcursosJuego].
Internal Exception: java.lang.NoSuchMethodException: model.ConcursosJuego._persistence_getjuego_vh()
i have no clue why i am getting this exception becuase the Entity "Juegos" has that methods, this is the Entity Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package model;
import java.io.Serializable;
import java.math.BigInteger;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
*
* #author user
*/
#Entity
#NamedQueries({
#NamedQuery(name = "Juego.findAll", query = "SELECT j FROM Juego j"),
#NamedQuery(name = "Juego.findById", query = "SELECT j FROM Juego j WHERE j.id = :id"),
#NamedQuery(name = "Juego.findByNombre", query = "SELECT j FROM Juego j WHERE j.nombre = :nombre"),
#NamedQuery(name = "Juego.findByUrl", query = "SELECT j FROM Juego j WHERE j.url = :url"),
#NamedQuery(name = "Juego.findByMultijugador", query = "SELECT j FROM Juego j WHERE j.multijugador = :multijugador"),
#NamedQuery(name = "Juego.findByTopejugadores", query = "SELECT j FROM Juego j WHERE j.topejugadores = :topejugadores"),
#NamedQuery(name = "Juego.findByEstado", query = "SELECT j FROM Juego j WHERE j.estado = :estado")})
public class Juego implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Basic(optional = false)
#NotNull
#Size(min = 1, max = 10)
private String id;
#Size(max = 255)
private String nombre;
#Size(max = 1000)
private String url;
private BigInteger multijugador;
private BigInteger topejugadores;
#Size(max = 1)
private String estado;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "juego", fetch = FetchType.LAZY)
private List<Partida> partidaList;
#JoinColumn(name = "RANKING_ID", referencedColumnName = "ID")
#ManyToOne(optional = false, fetch = FetchType.LAZY)
private Ranking ranking;
#JoinColumn(name = "CATEGORIA_ID", referencedColumnName = "ID")
#ManyToOne(optional = false, fetch = FetchType.LAZY)
private Categoria categoria;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "juego", fetch = FetchType.LAZY)
private List<InteraccionUsuarioJuego> interaccionUsuarioJuegoList;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "juego", fetch = FetchType.LAZY)
private List<ConcursosJuego> concursosJuegoList;
public Juego() {
}
public Juego(String id) {
this.id = id;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public BigInteger getMultijugador() {
return multijugador;
}
public void setMultijugador(BigInteger multijugador) {
this.multijugador = multijugador;
}
public BigInteger getTopejugadores() {
return topejugadores;
}
public void setTopejugadores(BigInteger topejugadores) {
this.topejugadores = topejugadores;
}
public String getEstado() {
return estado;
}
public void setEstado(String estado) {
this.estado = estado;
}
public List<Partida> getPartidaList() {
return partidaList;
}
public void setPartidaList(List<Partida> partidaList) {
this.partidaList = partidaList;
}
public Categoria getCategoria() {
return categoria;
}
public void setCategoria(Categoria categoria) {
this.categoria = categoria;
}
public List<InteraccionUsuarioJuego> getInteraccionUsuarioJuegoList() {
return interaccionUsuarioJuegoList;
}
public void setInteraccionUsuarioJuegoList(List<InteraccionUsuarioJuego> interaccionUsuarioJuegoList) {
this.interaccionUsuarioJuegoList = interaccionUsuarioJuegoList;
}
public List<ConcursosJuego> getConcursosJuegoList() {
return concursosJuegoList;
}
public void setConcursosJuegoList(List<ConcursosJuego> concursosJuegoList) {
this.concursosJuegoList = concursosJuegoList;
}
#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 Juego)) {
return false;
}
Juego other = (Juego) 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 "model.Juego[ id=" + id + " ]";
}
public Ranking getRanking() {
return ranking;
}
public void setRanking(Ranking ranking) {
this.ranking = ranking;
}
}
this is the application.xml
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" id="Application_ID" version="6">
<display-name>p_ear</display-name>
<module>
<ejb>p.jar</ejb>
</module>
<module>
<web>
<web-uri>p_web.war</web-uri>
<context-root>p_web</context-root>
</web>
</module>
</application>
i have tried eclipse link persistance and methods in other entities and it does work.
(This is the first entity that have more than 1 relation)
thanks

Related

java.lang.TypeNotPresentException: Type bookingSessionBean.Plot not present

I want to show the list of the plot from the database. I have created plot.java in package bookingSessionBean and viewPlot.java in package viewBean, but it doesn't work.
index.xhtml code:
<h:body>
<h1><h:outputText value="Selected Plot" /></h1>
<h:form>
<f:view>
<h:dataTable value="#{viewPlot.plots}" var="item">
<h:column>
<h:outputText value="#{item.plotno}" />
</h:column>
</h:dataTable>
</f:view>
</h:form>
</h:body>
viewPlot.java code
#ManagedBean
#Named(value = "viewPlot")
#SessionScoped
public class viewPlot implements Serializable {
#PersistenceContext(unitName = "2day4uPU")
private EntityManager em;
public viewPlot() {
}
public List<Plot> getPlots()
{
return em.createNamedQuery("Plot.findAll").getResultList();
}
}
Plot.java code
#Entity
#Table(name = "PLOT")
#XmlRootElement
#NamedQueries({
#NamedQuery(name = "Plot.findAll", query = "SELECT p FROM Plot p"),
#NamedQuery(name = "Plot.findByPlotno", query = "SELECT p FROM Plot p WHERE p.plotno = :plotno"),
#NamedQuery(name = "Plot.findByStartdate", query = "SELECT p FROM Plot p WHERE p.startdate = :startdate"),
#NamedQuery(name = "Plot.findByEnddate", query = "SELECT p FROM Plot p WHERE p.enddate = :enddate"),
#NamedQuery(name = "Plot.findByAvailableplot", query = "SELECT p FROM Plot p WHERE p.availableplot = :availableplot")})
public class Plot implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Basic(optional = false)
#NotNull
#Column(name = "PLOTNO")
private Integer plotno;
#Basic(optional = false)
#NotNull
#Column(name = "STARTDATE")
#Temporal(TemporalType.DATE)
private Date startdate;
#Basic(optional = false)
#NotNull
#Column(name = "ENDDATE")
#Temporal(TemporalType.DATE)
private Date enddate;
#Column(name = "AVAILABLEPLOT")
private Integer availableplot;
#JoinColumn(name = "ACCOMNO", referencedColumnName = "ACCOMNO")
#ManyToOne(optional = false)
private Accomodation accomno;
#JoinColumn(name = "SITENO", referencedColumnName = "SITENO")
#ManyToOne(optional = false)
private Site siteno;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "plotno")
private Collection<Booking> bookingCollection;
public Plot() {
}
public Plot(Integer plotno) {
this.plotno = plotno;
}
public Plot(Integer plotno, Date startdate, Date enddate) {
this.plotno = plotno;
this.startdate = startdate;
this.enddate = enddate;
}
public Integer getPlotno() {
return plotno;
}
public void setPlotno(Integer plotno) {
this.plotno = plotno;
}
public Date getStartdate() {
return startdate;
}
public void setStartdate(Date startdate) {
this.startdate = startdate;
}
public Date getEnddate() {
return enddate;
}
public void setEnddate(Date enddate) {
this.enddate = enddate;
}
public Integer getAvailableplot() {
return availableplot;
}
public void setAvailableplot(Integer availableplot) {
this.availableplot = availableplot;
}
public Accomodation getAccomno() {
return accomno;
}
public void setAccomno(Accomodation accomno) {
this.accomno = accomno;
}
public Site getSiteno() {
return siteno;
}
public void setSiteno(Site siteno) {
this.siteno = siteno;
}
#XmlTransient
public Collection<Booking> getBookingCollection() {
return bookingCollection;
}
public void setBookingCollection(Collection<Booking> bookingCollection) {
this.bookingCollection = bookingCollection;
}
#Override
public int hashCode() {
int hash = 0;
hash += (plotno != null ? plotno.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 Plot)) {
return false;
}
Plot other = (Plot) object;
if ((this.plotno == null && other.plotno != null) || (this.plotno != null && !this.plotno.equals(other.plotno))) {
return false;
}
return true;
}
#Override
public String toString() {
return "bookingSessionBean.Plot[ plotno=" + plotno + " ]";
}
}
[ how can I solve this error? ]

Managed Bean injection failure?

I have a bean that is supposed to retrieve people from a database and then put them in a list which is displayed on the webpage. I keep getting a managed bean injection failure though and it seems to be caused by some sort of link between the database and server getting screwed up.
here is the stack trace.
https://gist.github.com/blaxened/85a6861faf2373c26506
Here is the last part of the server log though it looks very similar to the stack trace.
https://gist.github.com/blaxened/f0bc6028d27cabcbd325
I know for a fact that the database/table is there
Here is my persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="com.jsfprohtml5_AIM_war_1.0PU" transaction-type="JTA">
<jta-data-source>jdbc/__default</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties/>
</persistence-unit>
</persistence>
This is the java class that connects to the database
package com.jsfprohtml5.firstapplication.model;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
*
* #author Black
*/
#Entity
#Table(name = "MYTABLE")
#NamedQueries({
#NamedQuery(name = "AimStaff.findAll", query = "SELECT a FROM AimStaff a"),
#NamedQuery(name = "AimStaff.findById", query = "SELECT a FROM AimStaff a WHERE a.id = :id"),
#NamedQuery(name = "AimStaff.findBySname", query = "SELECT a FROM AimStaff a WHERE a.sname = :sname"),
#NamedQuery(name = "AimStaff.findByDatejoined", query = "SELECT a FROM AimStaff a WHERE a.datejoined = :datejoined"),
#NamedQuery(name = "AimStaff.findByLocale", query = "SELECT a FROM AimStaff a WHERE a.locale = :locale"),
#NamedQuery(name = "AimStaff.findByPhone", query = "SELECT a FROM AimStaff a WHERE a.phone = :phone")})
public class AimStaff implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Basic(optional = false)
#NotNull
#Column(name = "ID")
private Integer id;
#Size(max = 255)
#Column(name = "SNAME")
private String sname;
#Size(max = 255)
#Column(name = "DATEJOINED")
private String datejoined;
#Size(max = 255)
#Column(name = "LOCALE")
private String locale;
// #Pattern(regexp="^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$", message="Invalid phone/fax format, should be as xxx-xxx-xxxx")//if the field contains phone or fax number consider using this annotation to enforce field validation
#Size(max = 100)
#Column(name = "PHONE")
private String phone;
public AimStaff() {
}
public AimStaff(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getSname() {
return sname;
}
public void setSname(String sname) {
this.sname = sname;
}
public String getDatejoined() {
return datejoined;
}
public void setDatejoined(String datejoined) {
this.datejoined = datejoined;
}
public String getLocale() {
return locale;
}
public void setLocale(String locale) {
this.locale = locale;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
#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 AimStaff)) {
return false;
}
AimStaff other = (AimStaff) 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 "com.jsfprohtml5.firstapplication.model.AimStaff[ id=" + id + " ]";
}
}
so I am unsure what is wrong. Let me know what other files need to be uploaded if any.
Your Table MYTABLE cannot be found by the Applicationserver. Can you verify that the server is able to connect and find the Table inside the configured datasource?
Can you post your persistence.xml?

Transactions in JSF Netbeans 7.3.1 generated code

I'm new to Java EE, following the learning by doing approach. In a very simple Mysql database with Netbeans 7.3.1 having a Patient table relates to a Person table, I'm having trouble understanding Netbeans generated code. I want to create a transaction where a Person and a Patient should be created and persisted with roll back possibility. Should i create a separate controller to handle such a transaction. Kindly help with a link to some similar example code. Code generated by Netbeans is below. (Some imports and redundant code removed)
Person.java
package entity;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
#Entity
#Table(name = "person")
#XmlRootElement
public class Person 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)
#NotNull
#Size(min = 1, max = 45)
#Column(name = "firstname")
private String firstname;
#Size(max = 255)
#Column(name = "email")
private String email;
#Size(max = 15)
#Column(name = "mobile")
private String mobile;
#Size(max = 15)
#Column(name = "residence")
private String residence;
#Size(max = 15)
#Column(name = "office")
private String office;
#Size(max = 255)
#Column(name = "address")
private String address;
#Size(max = 20)
#Column(name = "nic")
private String nic;
#Basic(optional = false)
#NotNull
#Column(name = "regdate")
#Temporal(TemporalType.DATE)
private Date regdate;
#Basic(optional = false)
#NotNull
#Column(name = "dob")
#Temporal(TemporalType.DATE)
private Date dob;
#Basic(optional = false)
#NotNull
#Size(min = 1, max = 45)
#Column(name = "lastname")
private String lastname;
#Basic(optional = false)
#NotNull
#Size(min = 1, max = 25)
#Column(name = "city")
private String city;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "personid")
private Collection<Patient> patientCollection;
public Person() {
}
public Person(Integer id) {
this.id = id;
}
public Person(Integer id, String firstname, Date regdate, Date dob, String lastname, String city) {
this.id = id;
this.firstname = firstname;
this.regdate = regdate;
this.dob = dob;
this.lastname = lastname;
this.city = city;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getResidence() {
return residence;
}
public void setResidence(String residence) {
this.residence = residence;
}
public String getOffice() {
return office;
}
public void setOffice(String office) {
this.office = office;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getNic() {
return nic;
}
public void setNic(String nic) {
this.nic = nic;
}
public Date getRegdate() {
return regdate;
}
public void setRegdate(Date regdate) {
this.regdate = regdate;
}
public Date getDob() {
return dob;
}
public void setDob(Date dob) {
this.dob = dob;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
#XmlTransient
public Collection<Patient> getPatientCollection() {
return patientCollection;
}
public void setPatientCollection(Collection<Patient> patientCollection) {
this.patientCollection = patientCollection;
}
}
Patient.java
package entity;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
#Entity
#Table(name = "patient")
#XmlRootElement
#NamedQueries({
#NamedQuery(name = "Patient.findAll", query = "SELECT p FROM Patient p"),
#NamedQuery(name = "Patient.findById", query = "SELECT p FROM Patient p WHERE p.id = :id"),
#NamedQuery(name = "Patient.findByPatientcode", query = "SELECT p FROM Patient p WHERE p.patientcode = :patientcode"),
#NamedQuery(name = "Patient.findByHistory", query = "SELECT p FROM Patient p WHERE p.history = :history"),
#NamedQuery(name = "Patient.findByExtPatientCode", query = "SELECT p FROM Patient p WHERE p.extPatientCode = :extPatientCode")})
public class Patient 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)
#NotNull
#Size(min = 1, max = 20)
#Column(name = "patientcode")
private String patientcode;
#Size(max = 255)
#Column(name = "history")
private String history;
#Size(max = 20)
#Column(name = "ExtPatientCode")
private String extPatientCode;
#JoinColumn(name = "personid", referencedColumnName = "id")
#ManyToOne(optional = false)
private Person personid;
public Patient() {
}
public Patient(Integer id) {
this.id = id;
}
public Patient(Integer id, String patientcode) {
this.id = id;
this.patientcode = patientcode;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getPatientcode() {
return patientcode;
}
public void setPatientcode(String patientcode) {
this.patientcode = patientcode;
}
public String getHistory() {
return history;
}
public void setHistory(String history) {
this.history = history;
}
public String getExtPatientCode() {
return extPatientCode;
}
public void setExtPatientCode(String extPatientCode) {
this.extPatientCode = extPatientCode;
}
public Person getPersonid() {
return personid;
}
public void setPersonid(Person personid) {
this.personid = personid;
}
}
AbstractFacade.java
package session;
import java.util.List;
import javax.persistence.EntityManager;
public abstract class AbstractFacade<T> {
private Class<T> entityClass;
public AbstractFacade(Class<T> entityClass) {
this.entityClass = entityClass;
}
protected abstract EntityManager getEntityManager();
public void create(T entity) {
getEntityManager().persist(entity);
}
public void edit(T entity) {
getEntityManager().merge(entity);
}
public void remove(T entity) {
getEntityManager().remove(getEntityManager().merge(entity));
}
public T find(Object id) {
return getEntityManager().find(entityClass, id);
}
public List<T> findAll() {
javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
cq.select(cq.from(entityClass));
return getEntityManager().createQuery(cq).getResultList();
}
public List<T> findRange(int[] range) {
javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
cq.select(cq.from(entityClass));
javax.persistence.Query q = getEntityManager().createQuery(cq);
q.setMaxResults(range[1] - range[0]);
q.setFirstResult(range[0]);
return q.getResultList();
}
}
PatientFacade.java
package session;
import entity.Patient;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
#Stateless
public class PatientFacade extends AbstractFacade<Patient> {
#PersistenceContext(unitName = "WebApplication4PU")
private EntityManager em;
#Override
protected EntityManager getEntityManager() {
return em;
}
public PatientFacade() {
super(Patient.class);
}
}
PersonFacade.java
package session;
import entity.Person;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
#Stateless
public class PersonFacade extends AbstractFacade<Person> {
#PersistenceContext(unitName = "WebApplication4PU")
private EntityManager em;
#Override
protected EntityManager getEntityManager() {
return em;
}
public PersonFacade() {
super(Person.class);
}
}
PersonController.java
package controllers;
import entity.Person;
import controllers.util.JsfUtil;
import controllers.util.PaginationHelper;
import session.PersonFacade;
import java.io.Serializable;
import java.util.ResourceBundle;
import javax.ejb.EJB;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.faces.model.SelectItem;
#Named("personController")
#SessionScoped
public class PersonController implements Serializable {
private Person current;
private DataModel items = null;
#EJB
private session.PersonFacade ejbFacade;
private PaginationHelper pagination;
private int selectedItemIndex;
public PersonController() {
}
public Person getSelected() {
if (current == null) {
current = new Person();
selectedItemIndex = -1;
}
return current;
}
private PersonFacade getFacade() {
return ejbFacade;
}
public PaginationHelper getPagination() {
if (pagination == null) {
pagination = new PaginationHelper(10) {
#Override
public int getItemsCount() {
return getFacade().count();
}
#Override
public DataModel createPageDataModel() {
return new ListDataModel(getFacade().findRange(new int[]{getPageFirstItem(), getPageFirstItem() + getPageSize()}));
}
};
}
return pagination;
}
public String prepareList() {
recreateModel();
return "List";
}
public String prepareView() {
current = (Person) getItems().getRowData();
selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
return "View";
}
public String prepareCreate() {
current = new Person();
selectedItemIndex = -1;
return "Create";
}
public String create() {
try {
getFacade().create(current);
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("PersonCreated"));
return prepareCreate();
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
return null;
}
}
public String prepareEdit() {
current = (Person) getItems().getRowData();
selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
return "Edit";
}
public String update() {
try {
getFacade().edit(current);
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("PersonUpdated"));
return "View";
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
return null;
}
}
public String destroy() {
current = (Person) getItems().getRowData();
selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
performDestroy();
recreatePagination();
recreateModel();
return "List";
}
public String destroyAndView() {
performDestroy();
recreateModel();
updateCurrentItem();
if (selectedItemIndex >= 0) {
return "View";
} else {
// all items were removed - go back to list
recreateModel();
return "List";
}
}
private void performDestroy() {
try {
getFacade().remove(current);
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("PersonDeleted"));
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
}
}
private void updateCurrentItem() {
int count = getFacade().count();
if (selectedItemIndex >= count) {
// selected index cannot be bigger than number of items:
selectedItemIndex = count - 1;
// go to previous page if last page disappeared:
if (pagination.getPageFirstItem() >= count) {
pagination.previousPage();
}
}
if (selectedItemIndex >= 0) {
current = getFacade().findRange(new int[]{selectedItemIndex, selectedItemIndex + 1}).get(0);
}
}
public DataModel getItems() {
if (items == null) {
items = getPagination().createPageDataModel();
}
return items;
}
private void recreateModel() {
items = null;
}
private void recreatePagination() {
pagination = null;
}
public String next() {
getPagination().nextPage();
recreateModel();
return "List";
}
public String previous() {
getPagination().previousPage();
recreateModel();
return "List";
}
public SelectItem[] getItemsAvailableSelectMany() {
return JsfUtil.getSelectItems(ejbFacade.findAll(), false);
}
public SelectItem[] getItemsAvailableSelectOne() {
return JsfUtil.getSelectItems(ejbFacade.findAll(), true);
}
public Person getPerson(java.lang.Integer id) {
return ejbFacade.find(id);
}
#FacesConverter(forClass = Person.class)
public static class PersonControllerConverter implements Converter {
#Override
public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
if (value == null || value.length() == 0) {
return null;
}
PersonController controller = (PersonController) facesContext.getApplication().getELResolver().
getValue(facesContext.getELContext(), null, "personController");
return controller.getPerson(getKey(value));
}
java.lang.Integer getKey(String value) {
java.lang.Integer key;
key = Integer.valueOf(value);
return key;
}
String getStringKey(java.lang.Integer value) {
StringBuilder sb = new StringBuilder();
sb.append(value);
return sb.toString();
}
}
}
PatientController.java
package controllers;
import entity.Patient;
import controllers.util.JsfUtil;
import controllers.util.PaginationHelper;
import session.PatientFacade;
import java.io.Serializable;
import java.util.ResourceBundle;
import javax.ejb.EJB;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.faces.model.SelectItem;
#Named("patientController")
#SessionScoped
public class PatientController implements Serializable {
private Patient current;
private DataModel items = null;
#EJB
private session.PatientFacade ejbFacade;
private PaginationHelper pagination;
private int selectedItemIndex;
public PatientController() {
}
public Patient getSelected() {
if (current == null) {
current = new Patient();
selectedItemIndex = -1;
}
return current;
}
private PatientFacade getFacade() {
return ejbFacade;
}
public PaginationHelper getPagination() {
if (pagination == null) {
pagination = new PaginationHelper(10) {
#Override
public int getItemsCount() {
return getFacade().count();
}
#Override
public DataModel createPageDataModel() {
return new ListDataModel(getFacade().findRange(new int[]{getPageFirstItem(), getPageFirstItem() + getPageSize()}));
}
};
}
return pagination;
}
public String prepareList() {
recreateModel();
return "List";
}
public String prepareView() {
current = (Patient) getItems().getRowData();
selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
return "View";
}
public String prepareCreate() {
current = new Patient();
selectedItemIndex = -1;
return "Create";
}
public String create() {
try {
getFacade().create(current);
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("PatientCreated"));
return prepareCreate();
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
return null;
}
}
public String prepareEdit() {
current = (Patient) getItems().getRowData();
selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
return "Edit";
}
public String update() {
try {
getFacade().edit(current);
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("PatientUpdated"));
return "View";
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
return null;
}
}
public String destroy() {
current = (Patient) getItems().getRowData();
selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
performDestroy();
recreatePagination();
recreateModel();
return "List";
}
public String destroyAndView() {
performDestroy();
recreateModel();
updateCurrentItem();
if (selectedItemIndex >= 0) {
return "View";
} else {
// all items were removed - go back to list
recreateModel();
return "List";
}
}
private void performDestroy() {
try {
getFacade().remove(current);
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("PatientDeleted"));
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
}
}
private void updateCurrentItem() {
int count = getFacade().count();
if (selectedItemIndex >= count) {
// selected index cannot be bigger than number of items:
selectedItemIndex = count - 1;
// go to previous page if last page disappeared:
if (pagination.getPageFirstItem() >= count) {
pagination.previousPage();
}
}
if (selectedItemIndex >= 0) {
current = getFacade().findRange(new int[]{selectedItemIndex, selectedItemIndex + 1}).get(0);
}
}
public DataModel getItems() {
if (items == null) {
items = getPagination().createPageDataModel();
}
return items;
}
private void recreateModel() {
items = null;
}
private void recreatePagination() {
pagination = null;
}
public String next() {
getPagination().nextPage();
recreateModel();
return "List";
}
public String previous() {
getPagination().previousPage();
recreateModel();
return "List";
}
public SelectItem[] getItemsAvailableSelectMany() {
return JsfUtil.getSelectItems(ejbFacade.findAll(), false);
}
public SelectItem[] getItemsAvailableSelectOne() {
return JsfUtil.getSelectItems(ejbFacade.findAll(), true);
}
public Patient getPatient(java.lang.Integer id) {
return ejbFacade.find(id);
}
#FacesConverter(forClass = Patient.class)
public static class PatientControllerConverter implements Converter {
#Override
public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
if (value == null || value.length() == 0) {
return null;
}
PatientController controller = (PatientController) facesContext.getApplication().getELResolver().
getValue(facesContext.getELContext(), null, "patientController");
return controller.getPatient(getKey(value));
}
java.lang.Integer getKey(String value) {
java.lang.Integer key;
key = Integer.valueOf(value);
return key;
}
String getStringKey(java.lang.Integer value) {
StringBuilder sb = new StringBuilder();
sb.append(value);
return sb.toString();
}
#Override
public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
if (object == null) {
return null;
}
if (object instanceof Patient) {
Patient o = (Patient) object;
return getStringKey(o.getId());
} else {
throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: " + Patient.class.getName());
}
}
}
}
Thanks in advance.
Fact: a single #Stateless EJB method call counts as a single full transaction.
Just make use of this fact. Create a new method in the #Stateless EJB which executes all necessary queries at once and then let your JSF backing bean call exactly that single method.
That's by the way exactly one of main reasons why EJBs exist: transparent transaction management. You seem to have missed this not unimportant fact while learning Java EE.

problem with select statement in many to one relational in EJB3 and JSF

Hi All
i wonder how to select between many to one relational
i have two table Sub_category and Items
sub category is own of relational, it contain list of Items
Two class follow:
#Entity
#Table(name = "item")
#NamedQueries({
#NamedQuery(name = "Items.findAll", query = "SELECT i FROM Items i"),
#NamedQuery(name = "Items.findByItemid", query = "SELECT i FROM Items i WHERE i.itemid = :itemid"),
#NamedQuery(name = "Items.findByItemName", query = "SELECT i FROM Items i WHERE i.itemName = :itemName"),
#NamedQuery(name = "Items.findByItemDescribe", query = "SELECT i FROM Items i WHERE i.itemDescribe = :itemDescribe"),
#NamedQuery(name = "Items.findByImg", query = "SELECT i FROM Items i WHERE i.img = :img"),
#NamedQuery(name = "Items.findByInstock", query = "SELECT i FROM Items i WHERE i.instock = :instock"),
#NamedQuery(name = "Items.findByPrice", query = "SELECT i FROM Items i WHERE i.price = :price"),
#NamedQuery(name = "Items.findByFine", query = "SELECT i FROM Items i WHERE i.fine = :fine"),
#NamedQuery(name = "Items.findByDateexp", query = "SELECT i FROM Items i WHERE i.dateexp = :dateexp"),
#NamedQuery(name = "Items.findByAuthor", query = "SELECT i FROM Items i WHERE i.author = :author"),
#NamedQuery(name = "Items.findByToprent", query = "SELECT i FROM Items i WHERE i.toprent = :toprent"),
#NamedQuery(name = "Items.findByStatus", query = "SELECT i FROM Items i WHERE i.status = :status")})
public class Items implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Basic(optional = false)
#Column(name = "itemid")
private Integer itemid;
#Basic(optional = false)
#Column(name = "item_name")
private String itemName;
#Column(name = "item_describe")
private String itemDescribe;
#Lob
#Column(name = "item_detail")
private String itemDetail;
#Column(name = "img")
private String img;
#Basic(optional = false)
#Column(name = "instock")
private int instock;
#Basic(optional = false)
#Column(name = "price")
private BigDecimal price;
#Basic(optional = false)
#Column(name = "fine")
private BigDecimal fine;
#Basic(optional = false)
#Column(name = "dateexp")
private int dateexp;
#Column(name = "author")
private String author;
#Column(name = "toprent")
private Integer toprent;
#Column(name = "status")
#Enumerated(EnumType.STRING)
private ItemStatus status;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "item")
private List<RentItem> rentItemList;
#JoinColumn(name = "cat_id", referencedColumnName = "subcatid")
#ManyToOne(optional = false)
private SubCat subCat;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "item")
private List<Cart> cartList;
public Items() {
}
public Items(Integer itemid) {
this.itemid = itemid;
}
public Items(Integer itemid, String itemName, int instock, BigDecimal price, BigDecimal fine, int dateexp) {
this.itemid = itemid;
this.itemName = itemName;
this.instock = instock;
this.price = price;
this.fine = fine;
this.dateexp = dateexp;
}
public Integer getItemid() {
return itemid;
}
public void setItemid(Integer itemid) {
this.itemid = itemid;
}
public String getItemName() {
return itemName;
}
public void setItemName(String itemName) {
this.itemName = itemName;
}
public String getItemDescribe() {
return itemDescribe;
}
public void setItemDescribe(String itemDescribe) {
this.itemDescribe = itemDescribe;
}
public String getItemDetail() {
return itemDetail;
}
public void setItemDetail(String itemDetail) {
this.itemDetail = itemDetail;
}
public String getImg() {
return img;
}
public void setImg(String img) {
this.img = img;
}
public int getInstock() {
return instock;
}
public void setInstock(int instock) {
this.instock = instock;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public BigDecimal getFine() {
return fine;
}
public void setFine(BigDecimal fine) {
this.fine = fine;
}
public int getDateexp() {
return dateexp;
}
public void setDateexp(int dateexp) {
this.dateexp = dateexp;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public Integer getToprent() {
return toprent;
}
public void setToprent(Integer toprent) {
this.toprent = toprent;
}
public ItemStatus getStatus() {
return status;
}
public void setStatus(ItemStatus status) {
this.status = status;
}
public List<RentItem> getRentItemList() {
return rentItemList;
}
public void setRentItemList(List<RentItem> rentItemList) {
this.rentItemList = rentItemList;
}
public SubCat getSubCat() {
return subCat;
}
public void setSubCat(SubCat subCat) {
this.subCat = subCat;
}
public List<Cart> getCartList() {
return cartList;
}
public void setCartList(List<Cart> cartList) {
this.cartList = cartList;
}
#Override
public int hashCode() {
int hash = 0;
hash += (itemid != null ? itemid.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 Items)) {
return false;
}
Items other = (Items) object;
if ((this.itemid == null && other.itemid != null) || (this.itemid != null && !this.itemid.equals(other.itemid))) {
return false;
}
return true;
}
#Override
public String toString() {
return "com.entity.Item[itemid=" + itemid + "]";
}
}
and subcategory class :
#Entity
#Table(name = "sub_cat")
#NamedQueries({
#NamedQuery(name = "SubCat.findAll", query = "SELECT s FROM SubCat s"),
#NamedQuery(name = "SubCat.findBySubcatid", query = "SELECT s FROM SubCat s WHERE s.subcatid = :subcatid"),
#NamedQuery(name = "SubCat.findBySubcatName", query = "SELECT s FROM SubCat s WHERE s.subcatName = :subcatName")})
public class SubCat implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Basic(optional = false)
#Column(name = "subcatid")
private Integer subcatid;
#Basic(optional = false)
#Column(name = "subcat_name")
private String subcatName;
#JoinColumn(name = "cat_parent", referencedColumnName = "cate_id")
#ManyToOne(optional = false)
private Category category;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "subCat")
private List<Items> itemList;
public SubCat() {
}
public SubCat(Integer subcatid) {
this.subcatid = subcatid;
}
public SubCat(Integer subcatid, String subcatName) {
this.subcatid = subcatid;
this.subcatName = subcatName;
}
public Integer getSubcatid() {
return subcatid;
}
public void setSubcatid(Integer subcatid) {
this.subcatid = subcatid;
}
public String getSubcatName() {
return subcatName;
}
public void setSubcatName(String subcatName) {
this.subcatName = subcatName;
}
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
public List<Items> getItemList() {
return itemList;
}
public void setItemList(List<Items> itemList) {
this.itemList = itemList;
}
#Override
public int hashCode() {
int hash = 0;
hash += (subcatid != null ? subcatid.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 SubCat)) {
return false;
}
SubCat other = (SubCat) object;
if ((this.subcatid == null && other.subcatid != null) || (this.subcatid != null && !this.subcatid.equals(other.subcatid))) {
return false;
}
return true;
}
#Override
public String toString() {
return "com.entity.SubCat[subcatid=" + subcatid + "]";
}
}
i have stateless bean for handle subcat such as:
#Stateless
#LocalBean
public class SubCatDAO {
#PersistenceContext(unitName = "mcGrawLibPro-ejbPU")
private EntityManager em;
public List<SubCat> retrieveAllSubCat(){
return em.createNamedQuery("SubCat.findAll").getResultList();
}
public SubCat updateSubCat(SubCat sc){
return em.merge(sc);
}
public void deleteSubCat(SubCat sc){
em.remove(em.merge(sc));
}
public SubCat addSubCat(SubCat sc){
em.persist(sc);
return sc;
}
public void persist(Object object) {
em.persist(object);
}
public List<Category> retrieveAllCat(){
return em.createNamedQuery("Category.findAll").getResultList();
}
public List<Items> getAllItemsSubCat(SubCat sub){
em.refresh(em.merge(sub));
List<Items> items = sub.getItemList();
ArrayList<Items> toReturn = new ArrayList<Items>(items.size());
for(Items iItem : items){
toReturn.add(iItem);
}
return toReturn;
}
// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method")
}
as you can see in stateless bean of subcat , i have written one method return List
and in JSF Managed Bean of subcat i write one method return List to view (JSF)
such as:
public List<Items> getAllItemsSub(){
return subCatDAO.getAllItemsSubCat(sub);
}
(subCatDAO is Stateless bean)
also in JSF Managened Bean of subcat i inital subcat follow:
public BeanConstructor(){
sub = new SubCat(1);
}
my problem is in view (JSF ) i was print list of items to show to user , but i can't get anything,i just see blank,
my code sample :
<h:ouputText value="#{bean.allItemSub.itemid}"/>
when i print bean.allItemSub it return [] <===
why it empty?
I don't really understand your implementation of the getAllItemsSubCat(SubCat sub) method in your EJB. I would rewrite it like this.
First, add a named query to find Items for given a SubCategory:
#NamedQuery(name = "Items.findBySubCat",
query = "SELECT i FROM Items i WHERE i.subCat = :subCat")
And rewrite the EJB method as follow:
public List<Items> getAllItemsSubCat(SubCat sub){
return em.createNamedQuery("Items.findBySubCat").setParameter("subCat", sub)
.getResultList();
}
Then, activate SQL logging (at the JPA provider level) to make sure the method actually returns something.

java.lang.IllegalArgumentException at javax.faces.component.UIComponentBase.validateId

Exception
java.lang.IllegalArgumentException: partidosPK.idEquipo
at javax.faces.component.UIComponentBase.validateId(UIComponentBase.java:551)
at javax.faces.component.UIComponentBase.setId(UIComponentBase.java:366)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply (ComponentTagHandlerDelegateImpl.java:168)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:114)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:91)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:120)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:204)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:114)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:91)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:120)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:204)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:114)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:91)
at com.sun.faces.facelets.tag.ui.DefineHandler.applyDefinition(DefineHandler.java:97)
at com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:172)
and keeps going... also
Entity bean
private String ganador;
#Column(name = "fecha")
#Temporal(TemporalType.TIMESTAMP)
private Date fecha;
#Column(name = "golesEquipoGanador")
private Integer golesEquipoGanador;
#Column(name = "golesEquipoPerdedor")
private Integer golesEquipoPerdedor;
#Column(name = "perdedor")
private String perdedor;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "partidos")
private Collection<Goleadores> goleadoresCollection;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "partidos")
private Collection<SancionesJugadores> sancionesJugadoresCollection;
#JoinColumns({
#JoinColumn(name = "idCampeonato", referencedColumnName = "idCampeonato", insertable = false, updatable = false),
#JoinColumn(name = "idPartido", referencedColumnName = "idEquipo", insertable = false, updatable = false)})
#ManyToOne(optional = false)
private EquiposPorCampeonato equiposPorCampeonato;
public Partidos() {
}
public Partidos(PartidosPK partidosPK) {
this.partidosPK = partidosPK;
}
public Partidos(int idCampeonato, int idEquipo, int idPartido) {
this.partidosPK = new PartidosPK(idCampeonato, idEquipo, idPartido);
}
public PartidosPK getPartidosPK() {
return partidosPK;
}
public void setPartidosPK(PartidosPK partidosPK) {
this.partidosPK = partidosPK;
}
public String getGanador() {
return ganador;
}
public void setGanador(String ganador) {
this.ganador = ganador;
}
public Date getFecha() {
return fecha;
}
public void setFecha(Date fecha) {
this.fecha = fecha;
}
public Integer getGolesEquipoGanador() {
return golesEquipoGanador;
}
public void setGolesEquipoGanador(Integer golesEquipoGanador) {
this.golesEquipoGanador = golesEquipoGanador;
}
public Integer getGolesEquipoPerdedor() {
return golesEquipoPerdedor;
}
public void setGolesEquipoPerdedor(Integer golesEquipoPerdedor) {
this.golesEquipoPerdedor = golesEquipoPerdedor;
}
public String getPerdedor() {
return perdedor;
}
public void setPerdedor(String perdedor) {
this.perdedor = perdedor;
}
public Collection<Goleadores> getGoleadoresCollection() {
return goleadoresCollection;
}
public void setGoleadoresCollection(Collection<Goleadores> goleadoresCollection) {
this.goleadoresCollection = goleadoresCollection;
}
public Collection<SancionesJugadores> getSancionesJugadoresCollection() {
return sancionesJugadoresCollection;
}
public void setSancionesJugadoresCollection(Collection<SancionesJugadores> sancionesJugadoresCollection) {
this.sancionesJugadoresCollection = sancionesJugadoresCollection;
}
public EquiposPorCampeonato getEquiposPorCampeonato() {
return equiposPorCampeonato;
}
public void setEquiposPorCampeonato(EquiposPorCampeonato equiposPorCampeonato) {
this.equiposPorCampeonato = equiposPorCampeonato;
}
#Override
public int hashCode() {
int hash = 0;
hash += (partidosPK != null ? partidosPK.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 Partidos)) {
return false;
}
Partidos other = (Partidos) object;
if ((this.partidosPK == null && other.partidosPK != null) || (this.partidosPK != null && !this.partidosPK.equals(other.partidosPK))) {
return false;
}
return true;
}
#Override
public String toString() {
return "" + partidosPK + "";
}
}
related primaryKey entitybean
#Embeddable
public class PartidosPK implements Serializable {
#Basic(optional = false)
#Column(name = "idCampeonato")
private int idCampeonato;
#Basic(optional = false)
#Column(name = "idEquipo")
private int idEquipo;
#Basic(optional = false)
#Column(name = "idPartido")
private int idPartido;
public PartidosPK() {
}
public PartidosPK(int idCampeonato, int idEquipo, int idPartido) {
this.idCampeonato = idCampeonato;
this.idEquipo = idEquipo;
this.idPartido = idPartido;
}
public int getIdCampeonato() {
return idCampeonato;
}
public void setIdCampeonato(int idCampeonato) {
this.idCampeonato = idCampeonato;
}
public int getIdEquipo() {
return idEquipo;
}
public void setIdEquipo(int idEquipo) {
this.idEquipo = idEquipo;
}
public int getIdPartido() {
return idPartido;
}
public void setIdPartido(int idPartido) {
this.idPartido = idPartido;
}
#Override
public int hashCode() {
int hash = 0;
hash += (int) idCampeonato;
hash += (int) idEquipo;
hash += (int) idPartido;
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 PartidosPK)) {
return false;
}
PartidosPK other = (PartidosPK) object;
if (this.idCampeonato != other.idCampeonato) {
return false;
}
if (this.idEquipo != other.idEquipo) {
return false;
}
if (this.idPartido != other.idPartido) {
return false;
}
return true;
}
#Override
public String toString() {
return "" + idCampeonato + ", " + idEquipo + ", " + idPartido + "";
}
}
Last but not least
#Entity
#Table(name = "equipos")
#NamedQueries({
#NamedQuery(name = "Equipos.findAll", query = "SELECT e FROM Equipos e"),
#NamedQuery(name = "Equipos.findByIdEquipo", query = "SELECT e FROM Equipos e WHERE e.idEquipo = :idEquipo"),
#NamedQuery(name = "Equipos.findByNombre", query = "SELECT e FROM Equipos e WHERE e.nombre = :nombre")})
public class Equipos implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Basic(optional = false)
#Column(name = "idEquipo")
private Integer idEquipo;
#Basic(optional = false)
#Column(name = "nombre")
private String nombre;
#JoinColumn(name = "idSexo", referencedColumnName = "idSexo")
#ManyToOne(optional = false)
private Sexos idSexo;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "idEquipo")
private Collection<Jugadores> jugadoresCollection;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "equipos")
private Collection<EquiposPorCampeonato> equiposPorCampeonatoCollection;
public Equipos() {
}
public Equipos(Integer idEquipo) {
this.idEquipo = idEquipo;
}
public Equipos(Integer idEquipo, String nombre) {
this.idEquipo = idEquipo;
this.nombre = nombre;
}
public Integer getIdEquipo() {
return idEquipo;
}
public void setIdEquipo(Integer idEquipo) {
this.idEquipo = idEquipo;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public Sexos getIdSexo() {
return idSexo;
}
public void setIdSexo(Sexos idSexo) {
this.idSexo = idSexo;
}
public Collection<Jugadores> getJugadoresCollection() {
return jugadoresCollection;
}
public void setJugadoresCollection(Collection<Jugadores> jugadoresCollection) {
this.jugadoresCollection = jugadoresCollection;
}
public Collection<EquiposPorCampeonato> getEquiposPorCampeonatoCollection() {
return equiposPorCampeonatoCollection;
}
public void setEquiposPorCampeonatoCollection(Collection<EquiposPorCampeonato> equiposPorCampeonatoCollection) {
this.equiposPorCampeonatoCollection = equiposPorCampeonatoCollection;
}
#Override
public int hashCode() {
int hash = 0;
hash += (idEquipo != null ? idEquipo.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 Equipos)) {
return false;
}
Equipos other = (Equipos) object;
if ((this.idEquipo == null && other.idEquipo != null) || (this.idEquipo != null && !this.idEquipo.equals(other.idEquipo))) {
return false;
}
return true;
}
#Override
public String toString() {
return "" + nombre + "";
}
}
Table scripts available if needed
Thank you very much.
Yes its spanish please bear with me!
Equipos == Teams;
Partidos == Matches;
Campeonatos == Championships;
This exception is related to the view, not to the model. The exception is telling that you've set a component ID with the value partidosPK.idEquipo like as follows:
<h:someComponent id="partidosPK.idEquipo">
However, this ID is illegal as per the rules. It contains a dot .. Remove it or replace by _ or -. The rules are the same as for the HTML/CSS identifiers.
In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A1 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, or a hyphen followed by a digit.

Resources