Hello guys, I am using Hibernate + Spring with netbeans to make a web application. I have it working correctly and displaying data from the DB. My problem is I only know how to do one hibernate query which is shown below.

How can I do insert/delete queries. For instance in my JSP page I have a button, how can I make it so when a user clicks on a button it deletes a specific record from the database. In essence how can I pass parameters to my controller. and can someone explain when/how I need to use DAO objects.

Thanks!

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller;

import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.HibernateUtil;
import org.hibernate.Session;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

/**
 *
 * @author Zombies
 */
public class TestimonialsController implements Controller {

    public ModelAndView handleRequest(HttpServletRequest hsr, HttpServletResponse hsr1)
        throws Exception
    {


        ModelAndView bc = new ModelAndView("testimonials");
        String out = new String ("testimonial list");



        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            session.beginTransaction();
            List result= session.createQuery("from Testimonial").list();
            bc.addObject("testimonials", result);
            session.getTransaction().commit();
        } catch (Exception e) {
            e.printStackTrace();
        }

        bc.addObject("message", out);
        return bc;
        }


  }

Which version of Hibernate are you using?

Which version of Hibernate are you using?

3.2.5 Hibernate

and Spring 3.0.2

Once you get SessionFactory you call for getCurrentSession() that will get you Session and through session you can save and update object

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.