I made a migration to hibernate
a crud and everything went fine until I lacked the last phase where two tables are related; but the problem is that you do not make the relationship.
I made a small relationship, but it does not work when I run it with jsp, it just sends me to the servlet.
This is the code that does not work for me. I already made the SELECT, INSERT, UPDATE
:
try (PrintWriter out = response.getWriter()) {
Datos dato= new Datos();
Cuadro cuadro= new Cuadro(request.getParameter("titulo"),request.getParameter("imagen"));
Lista lista= new Lista(cuadro,request.getParameter("miLista"));
dato.guardar(lista);
/*Constructor JDBC
dato.ejecutar("Insert into lista (mi_lista, cu_id_fk)"
+ " values ('"+request.getParameter("mi_lista")+"',"
+ " '"+request.getParameter("cu_id_fk")+"')");*/
response.sendRedirect("administrador.jsp");
}
Update: still sending me to servlet_lista
:
public class Servlet_Lista extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
Datos dato= new Datos();
Cuadro cuadro= new Cuadro(request.getParameter("titulo"),request.getParameter("imagen"));
Lista lista= new Lista(cuadro,request.getParameter("miLista"));
dato.guardar(lista);
/*Constructor JDBC
dato.ejecutar("Insert into lista (mi_lista, cu_id_fk)"
+ " values ('"+request.getParameter("mi_lista")+"',"
+ " '"+request.getParameter("cu_id_fk")+"')");*/
response.sendRedirect("administrador.jsp");
}
//metodo guardar
public void guardar(Object dato) {
SessionFactory sesion = NewHibernateUtil.getSessionFactory();
Session session;
session = sesion.openSession();
Transaction tra = session.beginTransaction();
session.save(dato);
tra.commit();
session.close();
}
//ser modelo lista
public class Lista implements java.io.Serializable {
private Integer idLista;
private String miLista;
private Cuadro cuadro;
public Lista() {
}
public Lista(Cuadro cuadro, String miLista) {
this.cuadro = cuadro;
this.miLista = miLista;
}
public Integer getIdLista() {
return this.idLista;
}
public void setIdLista(Integer idLista) {
this.idLista = idLista;
}
public Cuadro getCuadro() {
return this.cuadro;
}
public void setCuadro(Cuadro cuadro) {
this.cuadro = cuadro;
}
public String getMiLista() {
return this.miLista;
}
public void setMiLista(String miLista) {
this.miLista = miLista;
}