@Override
public List<Projet> getScenariosByProjet(int idProjet) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
String sql = "select * from projet where scenario="+idProjet;
Query query = session.createSQLQuery(sql);
List<Projet> scenarios = (List<Projet>) query.list();
return scenarios;
}
the class Projet :
public class Projet {
private int idProjet;
private String nomProjet;
private Set<Projet> scenarios = new HashSet<Projet>();
//.....
the hbm file :
<hibernate-mapping>
<class name="com.model.Projet" table="PROJET">
<id name="idProjet" type="int">
<column name="IDPROJET" />
<generator class="increment" />
</id>
<property name="nomProjet" type="java.lang.String">
<column name="NOMPROJET" />
</property>
<set name="scenarios" table="PROJET" inverse="false" lazy="true" order-by="SCENARIO">
<key>
<column name="SCENARIO" />
</key>
<one-to-many class="com.model.Projet" />
</set>
//.....
i'm getting this exception :
exception org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.model.Projet org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:927) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:822) javax.servlet.http.HttpServlet.service(HttpServlet.java:647) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796) javax.servlet.http.HttpServlet.service(HttpServlet.java:728) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
here is the method :
public ModelAndView saveProject(@RequestParam(value="action", required=false) String action){
List<Projet> scenarios = projetService.getScenariosByProjet(1);
model.addObject("scenarios", scenarios);
List<Projet> sousProjets = projetService.getSsProjetsByProjet(id);
model.addObject("sousprojets", sousProjets);
Iterator<Projet> scens = scenarios.iterator();
while(scens.hasNext()){
Projet projet2 = (Projet) scens.next();
System.out.println("projet scenario : " + projet2.getName);
}
return new ModelAndView("/resume","sousprojets", sousProjets);
}
Project
an incompatibleObject
, but currently it is impossible to say where. – Serge BallestasaveProject
(Controller.java:847) during a post. You should look (and show us ?) what happens in this method and what the associated form looks like – Serge Ballesta