error
when i am going to enrering data into associate table(order items table)
following error is occured. but the other tables are inserted successfully.
In a my OrderItem table form , i created a two combo boxes for selecting productid and orderid . combo boxes are working, data from product and order tables display successfully
problem is can not insert data in to order item table
error mesage
19:52:45,709 WARN JDBCExceptionReporter:38 - SQL Error: 1048, SQLState: S1000
19:52:45,709 ERROR JDBCExceptionReporter:46 - General error: Column 'order_id' c
annot be null
19:52:45,709 WARN JDBCExceptionReporter:38 - SQL Error: 1048, SQLState: S1000
19:52:45,709 ERROR JDBCExceptionReporter:46 - General error: Column 'order_id' c
annot be null
19:52:45,709 ERROR JDBCExceptionReporter:38 - Could not execute JDBC batch updat
e
java.sql.BatchUpdateException: General error: Column 'order_id' cannot be null
at com.mysql.jdbc.jdbc2.PreparedStatement.executeBatch(Unknown Source)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.
java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:118)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2309)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2259)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2185)
at test.hibernate.actions.NewOrderItems.doExecute(NewOrderItems.java:84)
at webwork.action.ActionSupport.execute(ActionSupport.java:151)
at webwork.dispatcher.GenericDispatcher.executeAction(GenericDispatcher.
java:131)
at webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:1
74)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:
2417)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatche
rValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:19
3)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:781)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:549)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
:589)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:666)
at java.lang.Thread.run(Thread.java:536)
19:52:45,725 ERROR SessionImpl:2267 - Could not synchronize database state with
session
net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:125)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2309)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2259)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2185)
at test.hibernate.actions.NewOrderItems.doExecute(NewOrderItems.java:84)
at webwork.action.ActionSupport.execute(ActionSupport.java:151)
at webwork.dispatcher.GenericDispatcher.executeAction(GenericDispatcher.
java:131)
at webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:1
74)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:
2417)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatche
rValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:19
3)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:781)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:549)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
:589)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:666)
at java.lang.Thread.run(Thread.java:536)
Caused by: java.sql.BatchUpdateException: General error: Column 'order_id' canno
t be null
at com.mysql.jdbc.jdbc2.PreparedStatement.executeBatch(Unknown Source)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.
java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:118)
... 37 more
net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:125)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2309)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2259)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2185)
at test.hibernate.actions.NewOrderItems.doExecute(NewOrderItems.java:84)
at webwork.action.ActionSupport.execute(ActionSupport.java:151)
at webwork.dispatcher.GenericDispatcher.executeAction(GenericDispatcher.
java:131)
at webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:1
74)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:
2417)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatche
rValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:19
3)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:781)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:549)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
:589)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:666)
at java.lang.Thread.run(Thread.java:536)
Caused by: java.sql.BatchUpdateException: General error: Column 'order_id' canno
t be null
at com.mysql.jdbc.jdbc2.PreparedStatement.executeBatch(Unknown Source)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.
java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:118)
... 37 more
hei error
i am using hibernate 2.1 and mysql
hi
i am new to thr hibernate, so i am doing some simple application,
so i have 3 tables.
here are the 3 tables.
CREATE TABLE ORDERS(
ID VARCHAR NOT NULL PRIMARY KEY,
ORDER_DATE TIMESTAMP NOT NULL,
PRICE_TOTAL DOUBLE NOT NULL)
CREATE TABLE PRODUCTS(
ID VARCHAR NOT NULL PRIMARY KEY,
NAME VARCHAR NOT NULL,
PRICE DOUBLE NOT NULL,
AMOUNT INTEGER NOT NULL)
CREATE TABLE ORDER_ITEMS(
ID VARCHAR NOT NULL PRIMARY KEY,
ORDER_ID VARCHAR NOT NULL,
i created asimple web application using hibernate/jsp/java/webworks/tomcat
i created aweb forms for enter each table values.( for order table and products table)
values are insetrd in to the above 2 tables successfully.problem occurs when i am going to display order vales in a another jsp.
then i got following error in the tomcat.
18:47:33,179 INFO ReflectHelper:149 - reflection optimizer disabled for: test.h
ibernate.data.OrderItem, NullPointerException: null
here are my mapping files and other java classes.
order.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="test.hibernate.data.Order" table="orders">
<id name="id" type="string" unsaved-value="null" >
<column name="id" sql-type="char(32)"
not-null="true"/>
<generator class="uuid.hex"/>
</id>
<property name="oname">
<column name="oname" sql-type="char(32)" not-null="true"/>
</property>
<property name="date">
<column name="order_date" sql-type="date" not-null="true"/>
</property>
<property name="priceTotal">
<column name="price_total" sql-type="double" not-null="true"/>
</property>
<set name="orderItems" table="items" inverse="true" cascade="all" lazy="false" sort="unsorted" batch-size="1" outer-join="auto">
<key column="order_id" />
<one-to-many class="test.hibernate.data.OrderItem" />
</set>
</class>
</hibernate-mapping>
product.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="test.hibernate.data.Product" table="products">
<!-- A 32 hex character is our surrogate key. It's automatically
generated by Hibernate with the UUID pattern. -->
<id name="id" type="string" unsaved-value="null" >
<column name="id" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<property name="name">
<column name="name" sql-type="char(255)" not-null="true"/>
</property>
<property name="price">
<column name="price" sql-type="double" not-null="true"/>
</property>
<property name="amount">
<column name="amount" sql-type="integer" not-null="true"/>
</property>
</class>
</hibernate-mapping>
orderItem.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="test.hibernate.data.OrderItem" table="items">
<!-- A 32 hex character is our surrogate key. It's automatically
generated by Hibernate with the UUID pattern. -->
<id name="id" type="string" unsaved-value="null" >
<column name="id" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<property name="orderId" insert="false" update="false">
<column name="order_id" sql-type="char(32)" not-null="true"/>
</property>
<property name="productId" insert="false" update="false">
<column name="product_id" sql-type="char(32)" not-null="true"/>
</property>
<property name="amount">
<column name="amount" sql-type="integer" not-null="true"/>
</property>
<property name="price">
<column name="price" sql-type="double" not-null="true"/>
</property>
<many-to-one name="order" class="test.hibernate.data.Order" column="order_id" />
<many-to-one name="product" class="test.hibernate.data.Product" cascade="save-update" column="product_id"/>
</class>
</hibernate-mapping>
here is my jsp for entering orderItems details
<html>
<head>
<title>Product List</title>
</head>
<%@ page import="java.util.List"%>
<%@ page import="java.util.Iterator"%>
<body>
<h1> Order Items </h1>
<%
test.hibernate.actions.GetProductName e=new test.hibernate.actions.GetProductName();
String s=e.doExecute();
java.util.List list=e.getProducts();
//System.out.println("list.size()="+list);
Iterator iter = list.iterator();
test.hibernate.actions.GetOrderName g=new test.hibernate.actions.GetOrderName();
String d=g.doExecute();
java.util.List list1=g.getProducts();
//System.out.println("list.size()="+list);
Iterator iter1 = list1.iterator();
%>
<form method="POST" action="orderitemevent.action">
<table>
<tr>
<td><b>Product Name</b></td><td><select name="productname">
<%
while (iter.hasNext()) {
test.hibernate.data.Product p = (test.hibernate.data.Product) iter.next();
String c=p.getId();
String a= p.getName();
double b=p.getPrice();
%>
<option value='<%=c%>'><%=a%>
<%
}
%>
</select> </td>
</tr>
<tr>
<td><b>Order Name</b></td><td><select name="ordername">
<%
while (iter1.hasNext()) {
test.hibernate.data.Order o = (test.hibernate.data.Order) iter1.next();
String f=o.getId();
String h=o.getOname();
%>
<option value='<%=f%>'><%=h%>
<%
}
%>
</select> </td>
</tr>
<tr>
<td><b>amount</b></td>
<td><input type="text" name="amount" /></td>
</tr>
<td><b>price</b></td>
<td><input type="text" name="price" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit"/></td>
</tr>
</table>
</body>
</html>
here are my java classes
package test.hibernate.actions;
import java.util.List;
import java.util.Date;
import java.text.DateFormat;
import webwork.action.ActionSupport;
import webwork.action.CommandDriven;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.HibernateException;
import test.hibernate.util.SessionManager;
import test.hibernate.data.Order;
import test.hibernate.data.OrderItem;
import test.hibernate.data.Product;
public class NewOrderItems extends ActionSupport implements CommandDriven {
private String oname;
private String pname;
private int amount;
private double priceTotal;
public String getOrdername() {
return oname;
}
public void setOrdername(String oname) {
this.oname = oname;
}
public String getProductname() {
return pname;
}
public void setProductname(String pname) {
this.pname = pname;
}
public double getPrice() {
return priceTotal;
}
public void setPrice(double priceTotal) {
this.priceTotal = priceTotal;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount=amount;
}
public String doExecute() {
try {
Configuration cfg=new Configuration().addClass(OrderItem.class).addClass(Order.class).addClass(Product.class);
//.addClass(Order.class).addClass(OrderItem.class).addClass(Product.class);
//.addClass(OrderItem.class).addClass(Product.class)
//Session s = SessionManager.getSession();
SessionFactory sf=cfg.buildSessionFactory();
Session sess=sf.openSession();
OrderItem event = new OrderItem();
event.setOrderId(oname);
event.setProductId(pname);
event.setAmount(amount);
event.setPrice(priceTotal);
sess.save(event);
sess.flush();
System.out.println("hei sucess");
//s.close();
return SUCCESS;
} catch (HibernateException e) {
e.printStackTrace();
System.out.println("hei error");
return ERROR;
}
}
public String doEnter() {
return INPUT;
}
}
this the class for display order items
package test.hibernate.actions;
import java.util.List;
import java.util.Date;
import java.text.DateFormat;
import webwork.action.ActionSupport;
import webwork.action.CommandDriven;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.HibernateException;
import test.hibernate.util.SessionManager;
import test.hibernate.data.Order;
import test.hibernate.data.OrderItem;
import test.hibernate.data.Product;
public class OrderList extends ActionSupport {
private List orders;
public List getOrders() {
return orders;
}
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();
Order event = new Order();
orders = sess.find("from test.hibernate.data.Order");
// orders = sess.find("select o from o in class test.hibernate.data.Order");
sess.close();
return SUCCESS;
} catch (HibernateException e) {
e.printStackTrace();
System.out.println("errrorrrrrrrrrrrrrrrrrrrrrrrrrrrrr");
return ERROR;
}
}
public String doEnter() {
return INPUT;
}
}
product are displaying successfully
thisn the productlist class
package test.hibernate.actions;
import java.util.List;
import webwork.action.ActionSupport;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.HibernateException;
import test.hibernate.util.SessionManager;
import test.hibernate.data.Product;
public class EventList extends ActionSupport {
private List products;
public List getProducts() {
return products;
}
public String doExecute() {
try {
Configuration cfg=new Configuration().addClass(test.hibernate.data.Product.class);
SessionFactory sf=cfg.buildSessionFactory();
Session sess=sf.openSession();
products = sess.find("select p from p in class test.hibernate.data.Product");
sess.close();
//select product from product in class test.hibernate.data.Product
return SUCCESS;
} catch (HibernateException e) {
e.printStackTrace();
return ERROR;
}
}
}
order.java
package test.hibernate.data;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.text.DateFormat;
public class Order {
private String id;
private String oname;
//private Date date;
private String date;
private double priceTotal;
private Set orderItems = new HashSet();
public Order() {
//this.date = new Date();
}
/**
* Add a Product to this Order. Product automatically becomes an OrderItem.
* The priceTotal is automatically updated.
*
* @param p Product to add to this Order
* @param amount amount of products to add
*/
public void addProduct(Product p, int amount) {
OrderItem orderItem = new OrderItem(this, p, amount);
this.priceTotal = this.priceTotal + p.getPrice() * amount;
this.orderItems.add(orderItem);
}
public String getOname(){
return oname;
}
public void setOname(String oname){
this.oname=oname;
}
public String getDate() {
return date;
}
public String getId() {
return id;
}
public Set getOrderItems() {
return orderItems;
}
public double getPriceTotal() {
return priceTotal;
}
public void setDate(String date) {
this.date = date;
}
// /*public void setDate(String odate) {
//
// try{
//
// DateFormat d = DateFormat.getDateInstance();
// this.date = d.parse(odate);
// }catch (Exception p){
//p.printStackTrace();
// System.out.println("errorrrrrrrrrrrrrrrr");
// }
// }*/
public void setId(String string) {
id = string;
}
public void setOrderItems(Set set) {
orderItems = set;
}
public void setPriceTotal(double d) {
priceTotal = d;
}
public String toString() {
String s = "[Order] id=" + id +
"\n priceTotal=" + priceTotal +
"\n date=" + date + "\n";
s = s + "Order items:\n";
Iterator i = orderItems.iterator();
String o = "";
while (i.hasNext()) {
OrderItem item = (OrderItem) i.next();
o = o + " " + item + "\n";
}
return s + o;
}
}
product.java
package test.hibernate.data;
public class Product {
private String id;
private String name;
private double price;
private int amount;
// ===============
public int getAmount() {
return amount;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public double getPrice() {
return price;
}
public void setAmount(int i) {
amount = i;
}
public void setId(String string) {
id = string;
}
public void setName(String string) {
name = string;
}
public void setPrice(double d) {
price = d;
}
public String toString() {
return "[Product] " + name + "(" + id + ") price=" + price + " amount=" + amount;
}
}
orderitem.java
package test.hibernate.data;
public class OrderItem {
/**
* Empty constructor to conform to JavaBeans convention.
*
*/
public OrderItem() {
// empty default constructor
}
/**
* Creates valid OrderItem.
* @param order to which this OrderItem belongs
* @param p from which this OrderItem is created
* @param amount
*/
public OrderItem(Order order, Product product, int amount) {
this.order = order;
this.product = product;
this.amount = amount;
product.setAmount(product.getAmount() - amount);
this.price = product.getPrice() * amount;
}
private String id;
private Product product;
private Order order;
private String productId;
private String orderId;
private double price;
private int amount;
public int getAmount() {
return amount;
}
public String getId() {
return id;
}
public Order getOrder() {
return order;
}
public String getOrderId() {
return order.getId();
}
public double getPrice() {
return price;
}
public Product getProduct() {
return product;
}
public String getProductId() {
return product.getId();
}
public void setAmount(int i) {
amount = i;
}
public void setId(String string) {
id = string;
}
public void setOrder(Order order) {
this.order = order;
}
public void setOrderId(String string) {
this.orderId = string;
}
public void setPrice(double d) {
price = d;
}
public void setProduct(Product product) {
this.product = product;
}
public void setProductId(String string) {
this.productId = string;
}
public String toString() {
return "[OrderItem] id=" + id +
"\n amount=" + amount +
"\n price=" + price +
"\n (" + product + ")";
}
}
REGARDS'
GIMHAN
PLS HELP ME
|