I have a JSP page where i have a dropdown list with different cities, and when i choose the city, i would like to display the result of a SQL request, which is a table wit multiple columns.
The dropdown list works fine, but the problem is that i can't display the table in the JSP. i'm getting the error:
java.lang.IllegalStateException: No data type for node: org.hibernate.hql.internal.ast.tree.IdentNode +-[IDENT] IdentNode: 'idDomaine' {originalText=idDomaine}
The class Projet, has a many-to one relation with chefprojet and with domaine.
Projet.java
package bean;
import java.util.HashSet; import java.util.Set;
public class Projet implements java.io.Serializable {
private static final long serialVersionUID = 1L;
public int id;
private String libelle;
private String site;
private String finalite;
private String date_actuelle;
private String date_debut;
private String date_previsionnelle;
private Domaine domaine;
private Set <Acteur> assignedActeurs = new HashSet<Acteur>(0);
private Set <Bénéficiaire> assignedBénéficiaires = new HashSet<Bénéficiaire>(0);
private Chefprojet chefprojet;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getLibelle() {
return libelle;
}
public void setLibelle(String libelle) {
this.libelle = libelle;
}
public String getSite() {
return site;
}
public void setSite(String site) {
this.site = site;
}
public String getFinalite() {
return finalite;
}
public void setFinalite(String finalite) {
this.finalite = finalite;
}
public String getDate_actuelle() {
return date_actuelle;
}
public void setDate_actuelle(String date_actuelle) {
this.date_actuelle = date_actuelle;
}
public String getDate_debut() {
return date_debut;
}
public void setDate_debut(String date_debut) {
this.date_debut = date_debut;
}
public String getDate_previsionnelle() {
return date_previsionnelle;
}
public void setDate_previsionnelle(String date_previsionnelle) {
this.date_previsionnelle = date_previsionnelle;
}
public Domaine getDomaine() {
return domaine;
}
public void setDomaine(Domaine domaine) {
this.domaine = domaine;
}
public Set<Acteur> getAssignedActeurs() {
return assignedActeurs;
}
public void setAssignedActeurs(Set<Acteur> assignedActeurs) {
this.assignedActeurs = assignedActeurs;
}
public Set<Bénéficiaire> getAssignedBénéficiaires() {
return assignedBénéficiaires;
}
public void setAssignedBénéficiaires(Set<Bénéficiaire> assignedBénéficiaires) {
this.assignedBénéficiaires = assignedBénéficiaires;
}
public Chefprojet getChefprojet() {
return chefprojet;
}
public void setChefprojet(Chefprojet chefprojet) {
this.chefprojet = chefprojet;
}
public Projet() {
super();
// TODO Auto-generated constructor stub
}
public Projet(String libelle, String site, String finalite,
String date_actuelle, String date_debut,
String date_previsionnelle, Domaine domaine, Chefprojet chefprojet) {
super();
this.libelle = libelle;
this.site = site;
this.finalite = finalite;
this.date_actuelle = date_actuelle;
this.date_debut = date_debut;
this.date_previsionnelle = date_previsionnelle;
this.domaine = domaine;
this.chefprojet = chefprojet;
}
}
Projet.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://ift.tt/UNuKEd">
<!-- Generated 25 avr. 2015 06:50:10 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="bean.Projet" table="PROJET">
<id name="id" type="int">
<column name="ID" />
<generator class="identity" />
</id>
<property name="libelle" type="java.lang.String">
<column name="LIBELLE" />
</property>
<property name="site" type="java.lang.String">
<column name="SITE" />
</property>
<property name="finalite" type="java.lang.String">
<column name="FINALITE" />
</property>
<property name="date_actuelle" type="java.lang.String">
<column name="DATE_ACTUELLE" />
</property>
<property name="date_debut" type="java.lang.String">
<column name="DATE_DEBUT" />
</property>
<property name="date_previsionnelle" type="java.lang.String">
<column name="DATE_PREVISIONNELLE" />
</property>
<many-to-one name="domaine" class="bean.Domaine" fetch="join">
<column name="IDDOMAINE" />
</many-to-one>
<set name="assignedActeurs" table="PROJET_ACTEUR" inverse="false" lazy="true" fetch="select" cascade="all">
<key>
<column name="ID" />
</key>
<many-to-many class="bean.Acteur">
<column name="IDACTEUR" not-null="true" />
</many-to-many>
</set>
<set name="assignedBénéficiaires" table="PROJET_BENEFICIAIRE" inverse="false" lazy="true" fetch="select" cascade="all">
<key>
<column name="ID" />
</key>
<many-to-many class="bean.Bénéficiaire">
<column name="IDBENEFICIAIRE" not-null="true" />
</many-to-many>
</set>
<many-to-one name="chefprojet" class="bean.Chefprojet" fetch="join">
<column name="ID_CHEF"/>
</many-to-one>
</class>
</hibernate-mapping>
liste.jsp
<%@page import="bean.Projet"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="org.hibernate.Query"%>
<%@page import="util.HibernateUtil"%>
<%@page import="org.hibernate.Session"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%
String variable = "";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://ift.tt/kTyqzh">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<%
List projects = (List) request.getAttribute("listProject");
if (projects == null)
projects = new ArrayList();
%>
<body>
<div class="page">
<div class="header">
<a href="index.html" id="logo"><img src="images/Captureocp.PNG" alt=""/></a>
<ul>
<li><a href="acceuil.jsp">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="blog.html">Blog</a></li>
<li class="selected"><a href="services.html">Services</a></li>
</ul>
</div>
</div>
</br>
</br>
<form method="post" action="liste">
<p>
<select name="sites">
<option value="">-- Choisir --</option>
<option value="Khouribga">Khouribga</option>
<option value="Casablanca">Casablanca</option>
<option value="Casablanca">Jorf Lasfar</option>
<option value="Casablanca">Benguerir</option>
<option value="Casablanca">Boucraa</option>
<option value="Casablanca">Youssoufia</option>
<option value="Casablanca">Laayoune</option>
<option value="Casablanca">Safi</option>
</select><br />
</p>
<div class="centre">
<input type="submit" value="Chercher" name="Chercher"/>
</div>
</br></br></br>
<table border="1" cellpadding="3pt" align="center">
<tr>
<td>Liste des projets :</td>
</tr>
<%
for (Iterator iterator=projects.iterator();iterator.hasNext();) {
Projet projet =(Projet) iterator.next();
%>
<tr>
<td><%=projet.getSite()%></td>
<td><%=projet.getLibelle()%></td>
<td><%=projet.getDate_actuelle()%></td>
<td><%=projet.getDate_debut()%></td>
<td><%=projet.getDate_previsionnelle()%></td>
<td><%=projet.getDomaine()%></td>
<td><%=projet.getChefprojet()%></td>
</tr>
<%
}
%>
</table>
</br></br></br>
</form>
</body>
</html>
ListeControllerServlet.java
package controller;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.hibernate.Query;
import org.hibernate.Session;
import util.HibernateUtil;
import dao.ProjetDAO;
public class listeControllerServlet extends HttpServlet {
protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession(true);
try {
Session session1=HibernateUtil.getSessionFactory().getCurrentSession();
String selected=request.getParameter("sites");
session1.beginTransaction();
Query qry = session1.createQuery("select site,libelle,finalite,date_actuelle,date_debut,date_previsionnelle,idDomaine,id_chef from Projet projet where site='"+selected+"'");
List list = qry.list();
request.setAttribute("listProject", list);
request.getRequestDispatcher("liste.jsp").forward(request, response);
session1.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Aucun commentaire:
Enregistrer un commentaire