Beginner |
|
Joined: Wed Mar 24, 2004 8:43 am Posts: 42
|
hi
how can we pass update commands to modify the existing record using hibernate sql,
i had tried as below showed.but did not work
error
nullpointer exception
here is the jsp file
<form method="POST" action="productupdate.action">
<%
some codes...
%>
<p align="center"><font color="#000000" size="6"><strong> Modify An Product </strong></font></p>
<div align="center">
<table width="80%" border="1">
<tr>
<td width="48%" bgcolor="#999999"> <div align="left">
<p><strong>Org ID</strong></p>
<p><strong>Org Name</strong></p>
</div></td>
<td width="52%"><p>
<input name="productid" type="text" size="35" disabled value="<%= oid%>">
</p>
<p>
<input name="name" type="text" size="35" value="<%= a%>">
</p></td>
</tr>
<tr>
<td bgcolor="#999999"> <div align="left"><strong>Product price</strong></div></td>
<td><input name="price" type="text" size="35"value="<%= b%>"></td>
</tr>
<tr>
<td bgcolor="#999999"> <div align="left"><strong>Product Amount</strong></div></td>
<td><input name="amount" type="text" size="35"value="<%= c%>"></td>
</tr>
productupdate.action=ProductModify
here is ProductModify class
public String getProductid() {
return title;
}
public void setProductid(String title) {
this.title = title;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
public String doExecute() {
try {
Configuration cfg=new Configuration().addClass(test.hibernate.data.Order.class).addClass(test.hibernate.data.OrderItem.class).addClass(Product.class);
SessionFactory sf=cfg.buildSessionFactory();
Session sess=sf.openSession();
tx=sess.beginTransaction();
/Product event = new Product();
Product event = (Product)sess.load(test.hibernate.data.Product.class,title);
//event.setId(title);
event.setName(name);
event.setAmount(amount);
event.setPrice(price);
sess.saveOrUpdate(event);
sess.flush();
//s.close();
System.out.println(" success");
return SUCCESS;
} catch (HibernateException e) {
e.printStackTrace();
System.out.println(" sorry error");
return ERROR;
}
}
[/u]
|
|