-1
私は安らかなプログラムをコーディングしようとしています。これを行うために、私はGeneric Mapper(Mapper.class)を作成しました。私は私のクラスuser.classすべてがOKですが、私はplanning.classする私のクラスを変更したときに、私はエラーを持っているエラー500とログなしのJersey RestFul
User.class
@Entity
@XmlRootElement
public class Utilisateur implements Serializable{
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
@Column(name = "UTILISATEUR_ID")
private int Id;
@NotNull
private String Login;
@NotNull
private String MotDePasse;
@NotNull
private String Prenom;
@NotNull
private String Nom;
@NotNull
private EnumTypeUtilisateur TypeUtilisateur;
@ManyToMany(mappedBy="Moniteurs", cascade=CascadeType.ALL)
private Collection<Planning> Plannings;
@ManyToMany(mappedBy="Moniteurs", cascade=CascadeType.ALL)
private Collection<Disponibilite> Disponibilites;
public Utilisateur(){
}
public Utilisateur(String Login, String MotDepasse, String Prenom, String Nom, EnumTypeUtilisateur TypeUtilisateur){
this.Login=Login;
this.MotDePasse=MotDePasse;
this.Prenom=Prenom;
this.Nom=Nom;
this.TypeUtilisateur=TypeUtilisateur;
}
public int getId() {
return Id;
}
public void setId(int Id) {
this.Id = Id;
}
public String getLogin() {
return Login;
}
public void setLogin(String Login) {
this.Login = Login;
}
public String getMotDePasse() {
return MotDePasse;
}
public void setMotDePasse(String MotDePasse) {
this.MotDePasse = MotDePasse;
}
public String getPrenom() {
return Prenom;
}
public void setPrenom(String Prenom) {
this.Prenom = Prenom;
}
public String getNom() {
return Nom;
}
public void setNom(String Nom) {
this.Nom = Nom;
}
public Collection<Planning> getPlanning() {
return Plannings;
}
public void setPlanningCollection(Collection<Planning> PlanningCollection) {
this.Plannings = PlanningCollection;
}
public Collection<Disponibilite> getDisponibilite() {
return Disponibilites;
}
public void setDisponibiliteCollection(Collection<Disponibilite> DisponibiliteCollection) {
this.Disponibilites = DisponibiliteCollection;
}
public EnumTypeUtilisateur getTypeUtilisateur() {
return TypeUtilisateur;
}
public void setTypeUtilisateur(EnumTypeUtilisateur TypeUtilisateur) {
this.TypeUtilisateur = TypeUtilisateur;
}
}
にそれを使用Planning.class
@Entity
@XmlRootElement
public class Planning implements Serializable {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
@Column(name = "PLANNING_ID")
private int Id;
@Column(name="DATE_EVENEMENT")
@Temporal(TemporalType.TIMESTAMP)
private Date dateEvenement;
@NotNull
private EnumTypePlanning Type;
@ManyToMany
@JoinTable(name="ActivitePlanning",
[email protected](name="PLANNING_ID", referencedColumnName="PLANNING_ID"),
[email protected](name="ACTIVITE_ID", referencedColumnName="ACTIVITE_ID"))
private Collection<Activite> Activites;
@ManyToOne
@JoinColumn(name="GROUPE_ID",insertable = false, updatable = false)
private Groupe Groupe;
@ManyToMany
@JoinTable(name="UtilisateurPlanning",
[email protected](name="PLANNING_ID", referencedColumnName="PLANNING_ID"),
[email protected](name="UTILISATEUR_ID", referencedColumnName="UTILISATEUR_ID"))
private Collection<Utilisateur> Moniteurs;
public Planning(){
}
public Planning(Date dateEvenement, EnumTypePlanning Type, Collection<Activite> Activite, Groupe Groupe){
this.dateEvenement = dateEvenement;
this.Type=Type;
this.Activites=Activite;
this.Groupe=Groupe;
}
public int getId() {
return Id;
}
public void setId(int Id) {
this.Id = Id;
}
public Date getDateEvenement() {
return dateEvenement;
}
public void setDateEvenement(Date dateEvenement) {
this.dateEvenement = dateEvenement;
}
public EnumTypePlanning getType() {
return Type;
}
public void setType(EnumTypePlanning Type) {
this.Type = Type;
}
public Collection<Activite> getActivites() {
return Activites;
}
public void setActivites(Collection<Activite> Activites) {
this.Activites = Activites;
}
public Groupe getGroupe(){
return Groupe;
}
public void setGroupe(Groupe Groupe) {
this.Groupe = Groupe;
}
public Collection<Utilisateur> getMoniteur() {
return Moniteurs;
}
public void setMoniteurCollection(Collection<Utilisateur> MoniteurCollection) {
this.Moniteurs = MoniteurCollection;
}
}
Mapper.class
public class Mapper<T> extends AbstractFacade implements IMapper<T> {
@PersistenceContext(unitName = "EJPlanningRestPU")
private EntityManager em;
private List<T> list;
public Mapper(Class T){
super(T);
EntityManagerFactory emf = Persistence.createEntityManagerFactory("EJPlanningRestPU");
em = emf.createEntityManager();
}
@Override
protected EntityManager getEntityManager() {
return em;
}
@Override
public void add(T itemA) {
ParameterIsNotNull(itemA);
super.<T>create(itemA);
}
@Override
public void update(T itemA) {
ParameterIsNotNull(itemA);
super.<T>edit(itemA);
}
@Override
public void delete(T itemA) {
ParameterIsNotNull(itemA);
super.<T>remove(itemA);
}
@Override
public T getById(int id) {
ParameterIsNotNull(id);
T item = (T)super.find(id);
return item;
}
@Override
public List getAll() {
list = super.findAll();
return list;
}
@Override
public void ParameterIsNotNull(Object param){
if(param == null){
throw new IllegalStateMessage(param.toString()+" a généré une erreur ! ");
}
}
AbstractFacade.class
public abstract class AbstractFacade<T> {
private Class<T> entityClass;
private List<T> list;
public AbstractFacade(Class<T> entityClass) {
this.entityClass = entityClass;
}
protected abstract EntityManager getEntityManager();
public T create(T entity) {
try {
getEntityManager().getTransaction().begin();
getEntityManager().persist(entity);
getEntityManager().getTransaction().commit();
return entity;
} catch (Exception e) {
System.out.println(e.getMessage());
}
return null;
}
public void edit(T entity) {
try {
getEntityManager().getTransaction().begin();
getEntityManager().merge(entity);
getEntityManager().getTransaction().commit();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public void remove(T entity) {
try {
getEntityManager().getTransaction().begin();
getEntityManager().remove(getEntityManager().merge(entity));
getEntityManager().getTransaction().commit();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public T find(Object id) {
try {
return getEntityManager().find(entityClass, id);
} catch (Exception e) {
return null;
}
}
public List<T> findAll() {
try {
javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
cq.select(cq.from(entityClass));
return getEntityManager().createQuery(cq).getResultList();
} catch (Exception e) {
return null;
}
}
public List<T> findRange(int[] range) {
try {
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] + 1);
q.setFirstResult(range[0]);
return q.getResultList();
} catch (Exception e) {
return null;
}
}
public List<T>findByOneParameter(String Table, Object param){
CriteriaBuilder criteriabuilder = getEntityManager().getCriteriaBuilder();
CriteriaQuery<T> q = criteriabuilder.createQuery(entityClass);
Root<T> c = q.from(entityClass);
ParameterExpression<Object> p = criteriabuilder.parameter(Object.class, Table);
q.select(c).where(criteriabuilder.equal(c.get(Table), p));
TypedQuery<T> query = getEntityManager().createQuery(q);
query.setParameter(p, param);
return list = query.getResultList();
}
public List<T>findBytwoParameter(String Table,String Table2, Object param, Object param2){
CriteriaBuilder criteriabuilder = getEntityManager().getCriteriaBuilder();
CriteriaQuery<T> q = criteriabuilder.createQuery(entityClass);
Root<T> c = q.from(entityClass);
ParameterExpression<Object> p = criteriabuilder.parameter(Object.class, Table);
ParameterExpression<Object> p2 = criteriabuilder.parameter(Object.class, Table2);
q.select(c).where(criteriabuilder.equal(c.get(Table2), p2),
criteriabuilder.equal(c.get(Table), p));
TypedQuery<T> query = getEntityManager().createQuery(q);
query.setParameter(p, param);
query.setParameter(p2, param2);
return list = query.getResultList();
}
public List<T>findBythreeParameter(String Table,String Table2,String Table3, Object param, Object param2, Object param3){
CriteriaBuilder criteriabuilder = getEntityManager().getCriteriaBuilder();
CriteriaQuery<T> q = criteriabuilder.createQuery(entityClass);
Root<T> c = q.from(entityClass);
ParameterExpression<Object> p = criteriabuilder.parameter(Object.class, Table);
ParameterExpression<Object> p2 = criteriabuilder.parameter(Object.class, Table2);
ParameterExpression<Object> p3 = criteriabuilder.parameter(Object.class, Table3);
q.select(c).where(criteriabuilder.equal(c.get(Table2), p2),
criteriabuilder.equal(c.get(Table), p),
criteriabuilder.equal(c.get(Table3), p3));
TypedQuery<T> query = getEntityManager().createQuery(q);
query.setParameter(p, param);
query.setParameter(p2, param2);
query.setParameter(p3, param3);
return list = query.getResultList();
}
public int count() {
try {
javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
javax.persistence.criteria.Root<T> rt = cq.from(entityClass);
cq.select(getEntityManager().getCriteriaBuilder().count(rt));
javax.persistence.Query q = getEntityManager().createQuery(cq);
return ((Long) q.getSingleResult()).intValue();
} catch (Exception e) {
return 0;
}
}
}
Utilisateur.Mapper
public class UtilisateurMapper extends AbstractFacade implements IUtilisateurMapper {
@PersistenceContext(unitName = "EJPlanningRestPU")
private EntityManager em;
private List<Utilisateur> list;
public UtilisateurMapper() {
super(Utilisateur.class);
EntityManagerFactory emf = Persistence.createEntityManagerFactory("EJPlanningRestPU");
em = emf.createEntityManager();
}
@Override
protected EntityManager getEntityManager() {
return em;
}
@Override
public Utilisateur getByPseudoOrMDP(String Table, String field, String Search) {
Utilisateur user = new Utilisateur();
list =super.findByOneParameter(Table, Search);
if(list.size()<=0){
throw new IllegalStateMessage(Search+" déjà utilisé !");
}else{
user = list.get(0);
}
return user;
}
@Override
public Utilisateur getByPseudoAndMDP(String pseudo, String MDP) {
Utilisateur user = new Utilisateur();
try{
list =super.findBytwoParameter("pseudo","mdp",pseudo,MDP);
user = list.get(0);
}catch(Exception e){
throw new IllegalStateMessage("Aucun utilisateur trouvé!");
}
return user;
}
}
PlanningMapper.Class
public class PlanningMapper extends AbstractFacade implements IPlanningMapper{
@PersistenceContext(unitName = "EJPlanningRestPU")
private EntityManager em;
private List<Planning> list;
public PlanningMapper() {
super(Planning.class);
EntityManagerFactory emf = Persistence.createEntityManagerFactory("EJPlanningRestPU");
em = emf.createEntityManager(); }
@Override
protected EntityManager getEntityManager() {
return em;
}
@Override
public Planning getByDateAndGroupe(String Date, String Groupe) {
Planning user = new Planning();
try{
list =super.findBytwoParameter("dateEvenement","Groupe",Date,Groupe);
user = list.get(0);
}catch(Exception e){
return null;
}
return user;
}
}
エラー画面: [500エラースキャン] [1]
私はtomcatコンソールのログにエラーがないと言ったように... –