[jboss-svn-commits] JBL Code SVN: r13537 - in labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action: lib and 10 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Jul 15 13:59:29 EDT 2007


Author: tcunning
Date: 2007-07-15 13:59:28 -0400 (Sun, 15 Jul 2007)
New Revision: 13537

Added:
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/esb-mappings.hbm.xml
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/lib/
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/lib/ext/
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/lib/ext/mysql-connector-java-3.1.12-bin.jar
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/jboss/
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/jboss/soa/
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/jboss/soa/esb/
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/jboss/soa/esb/samples/
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/jboss/soa/esb/samples/quickstart/
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/jboss/soa/esb/samples/quickstart/hibernateaction/
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/jboss/soa/esb/samples/quickstart/hibernateaction/GatewayRecord.java
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/jboss/soa/esb/samples/quickstart/hibernateaction/MyAction.java
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/jboss/soa/esb/samples/quickstart/hibernateaction/Order.java
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/jboss/soa/esb/samples/quickstart/hibernateaction/SessionFactorySingleton.java
Modified:
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/build.xml
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/create.sql
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/readme.txt
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/view/edit.jsp
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/view/update.jsp
Log:
bug:JBESB-696
Adding missing hibernate quickstart src files.     


Modified: labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/build.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/build.xml	2007-07-15 15:33:28 UTC (rev 13536)
+++ labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/build.xml	2007-07-15 17:59:28 UTC (rev 13537)
@@ -26,13 +26,14 @@
 	</target>
 
 	<target name="config" depends="compile">
+		<mkdir dir="build/classes/org/jboss/soa/esb/samples/quickstart/hibernateaction"/>
 		<copy file="hibernate.cfg.xml"
                         todir="build/classes"/>
-                <copy file="${basedir}/src/org/jboss/soa/esb/samples/quickstart/hibernateaction/esb-mappings.hbm.xml"
+                <copy file="esb-mappings.hbm.xml"
                         todir="build/classes/org/jboss/soa/esb/samples/quickstart/hibernateaction"/>	
 	</target>
 
-	<target name="build-ear" depends="compile, package-deployment">
+	<target name="build-ear" depends="compile, config, package-deployment">
 		<jar destfile="${build.dir}/${ant.project.name}.jar">
 			<fileset dir="${build.dir}/classes">
 				<include name="**"/>
@@ -76,16 +77,6 @@
 		</ear>	
 	</target>
   
-	<target name="runtest" depends="config"
-		description="Insert row data into hibernate polled by gateway">
-		<echo>basedir=${basedir}</echo>	
-		<echo>Insert row data into hibernate  polled by gateway</echo>
-
-		<java classname="org.jboss.soa.esb.samples.quickstart.hibernateaction.GatewayPopulator">
-			<classpath refid="hibernate-classpath"/>
-		</java>
-	</target>  
-
 	<target name="dropdb" 
 		description="drop database">
 		<echo>Drop database</echo>

Modified: labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/create.sql
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/create.sql	2007-07-15 15:33:28 UTC (rev 13536)
+++ labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/create.sql	2007-07-15 17:59:28 UTC (rev 13537)
@@ -1,4 +1,4 @@
--- drop database orders;
+drop database orders;
 create database orders;
 use orders;
 create table orders

Added: labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/esb-mappings.hbm.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/esb-mappings.hbm.xml	                        (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/esb-mappings.hbm.xml	2007-07-15 17:59:28 UTC (rev 13537)
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping>
+	<class name="org.jboss.soa.esb.samples.quickstart.hibernateaction.Order" table="orders">
+		<id name="id" column="unique_id" type="java.lang.Long" unsaved-value="0">
+			<generator class="identity"/>
+		</id>
+		<property name="product" type="java.lang.String" column="product"/>
+		<property name="quantity" type="java.lang.Integer" column="quantity"/>
+		<property name="price" type="java.lang.Float" column="price"/>
+	</class>
+</hibernate-mapping>

Added: labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/lib/ext/mysql-connector-java-3.1.12-bin.jar
===================================================================
(Binary files differ)


Property changes on: labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/lib/ext/mysql-connector-java-3.1.12-bin.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/readme.txt
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/readme.txt	2007-07-15 15:33:28 UTC (rev 13536)
+++ labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/readme.txt	2007-07-15 17:59:28 UTC (rev 13537)
@@ -31,7 +31,7 @@
 ===============
 	1.	install mysql if you have not already.
 	2.	start the mysql database
-	3.	edit mysql.proprties with the user and password to be used with mysql 
+	3.	edit hibernate.cfg.xml with the user, password, and connection settings  to be used with mysql 
 	4.	ant createdb
 
 
@@ -46,9 +46,12 @@
 	jbossesb.xml:
 	The JMS gateway and ESB configuration file. It is listening for new rows in the gateway table.
 
+	hibernate.cfg.xml:
+	The Hibernate configuration file.
+
 	create.sql:
-	Will create the database and tables.
+	Creates the database and tables.
 
 	lib:
-	Additional jars needed. For example jar for database drivers
+	Additional jars needed (ex mysql JDBC driver) 
 

Added: labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/jboss/soa/esb/samples/quickstart/hibernateaction/GatewayRecord.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/jboss/soa/esb/samples/quickstart/hibernateaction/GatewayRecord.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/jboss/soa/esb/samples/quickstart/hibernateaction/GatewayRecord.java	2007-07-15 17:59:28 UTC (rev 13537)
@@ -0,0 +1,46 @@
+package org.jboss.soa.esb.samples.quickstart.hibernateaction;
+
+public class GatewayRecord {
+	private Long id;	
+	private String data;
+	private String status;
+
+	public GatewayRecord() { }
+	
+	public GatewayRecord(String f_data, String f_status) {
+		id = new Long(0);
+		this.data = f_data;
+		this.status = f_status;	
+	}
+	
+	public Long getId() {
+		return id;
+	}
+		
+	public void setId(Long f_id) {
+		this.id = f_id;
+	}
+
+	public String getData() {
+		return data;
+	}
+
+	public void setData(String f_data) {
+		this.data = f_data;
+	}		
+
+	public String getStatus() {
+		return status;
+	}
+	
+	public void setStatus(String f_status) {
+		this.status = f_status;
+	}
+	
+	public String toString() {
+		return "id [" + id + "]"
+			+ "data [" + data + "]  " 
+			+ "status [" + status + "] ";
+	}
+}
+

Added: labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/jboss/soa/esb/samples/quickstart/hibernateaction/MyAction.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/jboss/soa/esb/samples/quickstart/hibernateaction/MyAction.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/jboss/soa/esb/samples/quickstart/hibernateaction/MyAction.java	2007-07-15 17:59:28 UTC (rev 13537)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.samples.quickstart.hibernateaction;
+
+import org.jboss.soa.esb.actions.AbstractActionLifecycle;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * MyAction displays the messages that the Hibernate Event Listener sends.     The Order is 
+ * taken from the body of the message and then displayed to the console.
+ * 
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
+ * @since Version 4.2
+ */
+public class MyAction extends AbstractActionLifecycle
+{
+	protected ConfigTree _config;
+	  
+	public MyAction(ConfigTree config) { _config = config; } 
+  
+	public Message noOperation(Message message) { return message; } 
+
+	/**
+	 * Display the Order in the body of the message
+	 * @param message message
+	 * @return message
+	 * @throws Exception
+	 */
+	public Message displayMessage(Message message) {		
+		logHeader();
+		Order o = (Order) message.getBody().get(ListenerTagNames.HIBERNATE_OBJECT_DATA_TAG);
+		System.out.println(o.toString());
+		logFooter();
+		return message;         	
+	}
+  
+	/**
+	 * Display a header log line.
+	 */
+	private void logHeader() {
+		System.out.println("\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
+	}
+	
+	/**
+	 * Display a footer log line.
+	 */
+	private void logFooter() {
+		System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n");
+	}
+}

Added: labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/jboss/soa/esb/samples/quickstart/hibernateaction/Order.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/jboss/soa/esb/samples/quickstart/hibernateaction/Order.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/jboss/soa/esb/samples/quickstart/hibernateaction/Order.java	2007-07-15 17:59:28 UTC (rev 13537)
@@ -0,0 +1,134 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.samples.quickstart.hibernateaction;
+
+import java.io.Serializable;
+
+/**
+ * Order is the serialized object that this example is based around.   It
+ * contains a product name, the quantity of that product ordered, and the
+ * price per unit of the product.    It is serializable so that it can
+ * be bundled up in a message, and the JSPs 
+ * 
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
+ * @since Version 4.2
+ */
+public class Order implements Serializable {
+	private static final long serialVersionUID = -4620754343715487457L;
+	private Long id;	
+	private String product;
+	private Integer quantity;
+	private Float price; 
+
+	/**
+	 * Constructor that takes no values. 
+	 */
+	public Order() { }
+	
+	/**
+	 * Cosntructor - sets the product, quantity, price, and sets the id
+	 * to a default value.
+	 * @param f_product product name
+	 * @param f_quantity quantity of products
+	 * @param f_price price of one product item
+	 */
+	public Order(String f_product, Integer f_quantity, Float f_price) {
+		id = new Long(0);
+		this.product = f_product;
+		this.quantity = f_quantity;
+		this.price = f_price;	
+	}
+	
+	/**
+	 * Id getter.
+	 * @return id
+	 */
+	public Long getId() {
+		return id;
+	}
+		
+	/**
+	 * Id mutator
+	 * @param f_id id
+	 */
+	public void setId(Long f_id) {
+		this.id = f_id;
+	}
+
+	/**
+	 * Product getter.
+	 * @return product name
+	 */
+	public String getProduct() {
+		return product;
+	}	
+	
+	/**
+	 * Product mutator.
+	 * @param f_product product name
+	 */
+	public void setProduct(String f_product) {
+		product = f_product;
+	}
+
+	/**
+	 * Product quantity getter.
+	 * @return product quantity
+	 */
+	public Integer getQuantity() {
+		return quantity;
+	}
+
+	/** 
+	 * Product quantity mutator.
+	 * @param f_quantity product quantity
+	 */
+	public void setQuantity(Integer f_quantity) {
+		this.quantity = f_quantity;
+	}		
+
+	/**
+	 * Product price getter.
+	 * @return product price
+	 */
+	public Float getPrice() {
+		return price;
+	}
+	
+	/**
+	 * Product price mutator
+	 * @param f_price product price
+	 */
+	public void setPrice(Float f_price) {
+		this.price = f_price;
+	}
+	
+	/* (non-Javadoc)
+	 * @see java.lang.Object#toString()
+	 */
+	public String toString() {
+		return "id [" + id + "]"
+			+ "quantity [" + quantity + "]  " 
+			+ "price [" + price + "] ";
+	}
+}
+

Added: labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/jboss/soa/esb/samples/quickstart/hibernateaction/SessionFactorySingleton.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/jboss/soa/esb/samples/quickstart/hibernateaction/SessionFactorySingleton.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/src/org/jboss/soa/esb/samples/quickstart/hibernateaction/SessionFactorySingleton.java	2007-07-15 17:59:28 UTC (rev 13537)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.samples.quickstart.hibernateaction;
+
+import javax.naming.InitialContext;
+
+import org.apache.log4j.Logger;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+
+/**
+ * SessionFactorySingleton initializes a SessionFactory by looking it up
+ * in the JNDI InitialContext.     In order for the Hibernate Interceptor
+ * to work, it is very important that the same SessionFactory object is 
+ * used by the ESB and the client code, so this example uses the SessionFactory
+ * that the ESB has bound to JNDI.    
+ * 
+ * @author tcunning at redhat.com
+ */
+public class SessionFactorySingleton {
+	private SessionFactorySingleton() {
+	}
+
+	private static final Configuration config = new Configuration();
+	private static Logger logger = Logger.getLogger(SessionFactorySingleton.class);
+	private static SessionFactory sf;
+
+	private static String CONFIG_FILE = "hibernate.cfg.xml";
+	private static final String HIBERNATE_JNDI = "SessionFactory";
+
+	
+	/**
+	 * Return the SessionFactory, or initialize it if it is null.
+	 * @return SessionFactory
+	 */
+	public static SessionFactory getInstance() {
+		if (sf == null) {
+			init();		
+		}
+		return sf;	
+	}
+
+	/**
+	 * Initialize the sessionFactory by grabbing it out of the JNDI 
+	 * InitialContext.     It is very important that the example uses the
+	 * same SessionFactory object that is initialized by the ESB Hibernate
+	 * Listener because hibernate events can only be intercepted on the 
+	 * SessionFactory that the interceptor is set on.    By grabbing
+	 * the SessionFactory out of JNDI, we guarantee that we do that, even
+	 * in the case of a .ear redeploy.
+	 */
+	private static synchronized void init() {
+		try {
+			String jndiName = config.getProperty(HIBERNATE_JNDI);
+			if (jndiName == null) {
+				jndiName = HIBERNATE_JNDI;
+			}
+			
+			if (jndiName != null) {
+				InitialContext ic = new InitialContext();
+				sf = (SessionFactory) ic.lookup(jndiName);
+			} else {
+				sf = null;
+			}	
+		} catch (Exception e) {
+			e.printStackTrace();	
+		}
+		
+		if (sf == null) {
+			logger.error("Could not find SessionFactory in JNDI - Interceptors will not work!");
+			config.configure(CONFIG_FILE);
+			sf = config.buildSessionFactory();
+		}
+	}
+
+	/**
+	 * Close the sessionFactory and set the class's sessionFactory to null.
+	 */
+	public static void close() {
+		if (sf != null) {
+			sf.close();	
+		}
+		sf = null;
+	}
+}

Modified: labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/view/edit.jsp
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/view/edit.jsp	2007-07-15 15:33:28 UTC (rev 13536)
+++ labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/view/edit.jsp	2007-07-15 17:59:28 UTC (rev 13537)
@@ -27,14 +27,11 @@
 	try {
 		tx = sess.beginTransaction();
 		order = (Order) sess.load (Order.class, new Long(id));
-		tx.commit();
-	} catch (Exception e) {
-		e.printStackTrace();
-	}
+
 %>
 
 <body>
-	<form id="orderRequest" action="insert.jsp" method="post">
+	<form id="orderRequest" action="update.jsp" method="post">
 	<table width="100%" border="0" cellpadding="10" cellspacing="3">
 		<tr><td>Product</td><td><input type="text" 
 			value="<%=order.getProduct()%>"
@@ -45,8 +42,17 @@
 		<tr><td>Price</td><td><input type="text" 
 			value="<%=order.getPrice()%>" 
 			name="price" id="price"/></td></tr>
+		<input type="hidden" value="<%=id%>" name="id" id="id"/>
 		<tr><td><input type="submit" value="submit"></td></tr>
 	</table>
 	</form>
 </body>
 </html>
+<%
+		tx.commit();
+	} catch (Exception e) {
+		e.printStackTrace();
+	}
+%>
+
+

Modified: labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/view/update.jsp
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/view/update.jsp	2007-07-15 15:33:28 UTC (rev 13536)
+++ labs/jbossesb/trunk/product/samples/quickstarts/helloworld_hibernate_action/view/update.jsp	2007-07-15 17:59:28 UTC (rev 13537)
@@ -1,5 +1,6 @@
 <%@ page import="java.util.Iterator" %>
 <%@ page import="java.util.List" %>
+<%@ page import="org.hibernate.Query" %>
 <%@ page import="org.hibernate.Session" %>
 <%@ page import="org.hibernate.Transaction" %>
 <%@ page import="org.jboss.soa.esb.samples.quickstart.hibernateaction.*" %>
@@ -7,22 +8,20 @@
 	String product = request.getParameter("product");
 	String quantString = request.getParameter("quantity");
 	String priceString = request.getParameter("price");
-
+	String idString = request.getParameter("id");
+	
+	long id = Long.parseLong(idString);
 	int quantity = Integer.parseInt(quantString);
 	float price = Float.parseFloat(priceString);
-
+	
 	Transaction tx = null;
 	Session sess = SessionFactorySingleton.getInstance().getCurrentSession();
 	try {
 		tx = sess.beginTransaction();
-		Query q = sess.createQuery("update Order "
-			+ "set product = :product, "
-			+ "set quantity = :quantity, "
-			+ "set price = :price");
-		q.setString("product", product);
-		q.setInteger("quantity", new Integer(quantity));
-		q.setLong("price", new Long(price));
-		q.executeUpdate();
+		Order order = (Order) sess.get(Order.class, new Long(id));
+		order.setProduct(product);
+		order.setQuantity(new Integer(quantity));
+		order.setPrice(new Float(price));
 		tx.commit();
 	} catch (Exception e) {
 		e.printStackTrace();
@@ -30,7 +29,9 @@
 			tx.rollback();
 		}
 	} finally {
-		sess.close();
+		if (sess.isOpen()) {
+			sess.close();
+		}
 	}
 
 	response.sendRedirect(request.getContextPath() + "/list.jsp");	




More information about the jboss-svn-commits mailing list