Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Ruby on Rails and J2EE: Is there room for both?

Two Web application frameworks compared

Return to article


Listing 1. DeleteOrderAction.java
// Package and Import statements omitted

01 public class DeleteOrderAction extends Action {
02
03   public ActionForward execute(ActionMapping mapping, ActionForm form,
04            HttpServletRequest req, HttpServletResponse res) throws Exception {
05        
06     String value = req.getParameter("id");     // Get the order id from the request
07     Long id = new Long(value);
08
09     deleteOrder(id);
10
11     return mapping.findForward("success");  // Forward to ListOrdersAction
12   }
13
14   private void deleteOrder(Long id) {
15     Session session = HibernateUtil.currentSession();  // Get a session object
16     Transaction tx = null;
17  
18     try {
19       tx = session.beginTransaction();               // Begin the transaction
20       session.delete(new Order(id));                 // Delete the Order object
21       tx.commit();                                   // Commit the transaction
22     } finally {
23       HibernateUtil.closeSession();                  // Close the session
24     }
25   }
26 }

Return to article