I config many-to-one in child, but it also throws Exception.
hbm.xml
Code:
<hibernate-mapping>
<class name="com.dealeasy.ems.monitor.table.DePurchaseOrderModel" table="de_purchase_order">
<id column="id" name="id" type="java.lang.Long">
<generator class="identity"/>
</id>
<property column="PO_NO" length="15" name="poNo" not-null="true" type="java.lang.String"/>
<property column="INVOICE_NO" length="15" name="invoiceNo" type="java.lang.String"/>
<property column="ORDER_DATE" length="23" name="orderDate" type="java.util.Date"/>
<property column="CUSTORMS_DECLARATION_NO" length="80" name="custormsDeclarationNo" type="java.lang.String"/>
<set name="poLines" lazy="false" outer-join="true" cascade="save-update" inverse="true">
<key column="PURC_ORDER_ID"/>
<one-to-many class="com.dealeasy.ems.monitor.table.DePurchaseOrderLineModel"/>
</set>
</class>
<class name="com.dealeasy.ems.monitor.table.DePurchaseOrderLineModel" table="de_purchase_order_line">
<id column="id" name="id" type="java.lang.Long">
<generator class="identity"/>
</id>
<many-to-one name="purcOrder" class="com.dealeasy.ems.monitor.table.DePurchaseOrderModel" column="PURC_ORDER_ID"/>
<property column="PART_ID" length="15" name="partId" not-null="true" type="java.lang.String"/>
<property column="DESCRIPTION" length="40" name="description" type="java.lang.String"/>
<property column="ORDER_QTY" length="14" name="orderQty" type="java.lang.Double"/>
<property column="UNIT_PRICE" length="15" name="unitPrice" type="java.lang.Double"/>
<property column="TOTAL_SUM" length="18" name="totalSum" type="java.lang.Double"/>
</class>
</hibernate-mapping>
Insert data:
Code:
DePurchaseOrderModel insertModel = new DePurchaseOrderModel();
insertModel.setInvoiceNo("222");
insertModel.setPoNo("111");
DePurchaseOrderLineModel line1 = new DePurchaseOrderLineModel();
line1.setPartId("324-45");
line1.setDescription("dsfd");
line1.setUnitPrice(new Double(34.32));
DePurchaseOrderLineModel line2 = new DePurchaseOrderLineModel();
line2.setPartId("436-7685");
line2.setDescription("gfhgf");
line2.setUnitPrice(new Double(56.31));
Set setLine = new HashSet();
setLine.add(line1);
setLine.add(line2);
insertModel.setPoLines(setLine);
purchaseOrder.addPO(insertModel);
Method addPO:
Code:
public void addPO(DePurchaseOrderModel model) throws DException{
try{
beginTransaction();
Session s = super.currentSession();
s.save(model);
commitTransaction();
} catch(HibernateException ex){
log.error("Exception in PurchaseOrder.addPO", ex);
try{
rollbackTransaction();
} catch(HibernateException ex1){
}
}finally{
forceReleaseResource();
}
}
Hibernate log:
Code:
Hibernate: insert into de_purchase_order (PO_NO, INVOICE_NO, ORDER_DATE, CUSTORMS_DECLARATION_NO) values (?, ?, ?, ?)
Hibernate: select @@identity
Hibernate: insert into de_purchase_order_line (PURC_ORDER_ID, PART_ID, DESCRIPTION, ORDER_QTY, UNIT_PRICE, TOTAL_SUM) values (?, ?, ?, ?, ?, ?)
2004-02-25 09:57:36,562(2109) [main] WARN net.sf.hibernate.util.JDBCExceptionReporter - SQL Error: 515, SQLState: HY000
2004-02-25 09:57:36,562(2109) [main] ERROR net.sf.hibernate.util.JDBCExceptionReporter - [Microsoft][SQLServer JDBC Driver][SQLServer]Cannot insert the value NULL into column 'PURC_ORDER_ID', table 'ems_monitor.dbo.de_purchase_order_line'; column does not allow nulls. INSERT fails.
2004-02-25 09:57:36,593(2140) [main] WARN net.sf.hibernate.util.JDBCExceptionReporter - SQL Error: 3621, SQLState: HY000
2004-02-25 09:57:36,593(2140) [main] ERROR net.sf.hibernate.util.JDBCExceptionReporter - [Microsoft][SQLServer JDBC Driver][SQLServer]The statement has been terminated.
2004-02-25 09:57:36,593(2140) [main] WARN net.sf.hibernate.util.JDBCExceptionReporter - SQL Error: 515, SQLState: HY000
2004-02-25 09:57:36,593(2140) [main] ERROR net.sf.hibernate.util.JDBCExceptionReporter - [Microsoft][SQLServer JDBC Driver][SQLServer]Cannot insert the value NULL into column 'PURC_ORDER_ID', table 'ems_monitor.dbo.de_purchase_order_line'; column does not allow nulls. INSERT fails.
2004-02-25 09:57:36,593(2140) [main] WARN net.sf.hibernate.util.JDBCExceptionReporter - SQL Error: 3621, SQLState: HY000
2004-02-25 09:57:36,593(2140) [main] ERROR net.sf.hibernate.util.JDBCExceptionReporter - [Microsoft][SQLServer JDBC Driver][SQLServer]The statement has been terminated.
2004-02-25 09:57:36,593(2140) [main] ERROR net.sf.hibernate.util.JDBCExceptionReporter - could not insert: [com.dealeasy.ems.monitor.table.DePurchaseOrderLineModel]
java.sql.SQLException: [Microsoft][SQLServer JDBC Driver][SQLServer]Cannot insert the value NULL into column 'PURC_ORDER_ID', table 'ems_monitor.dbo.de_purchase_order_line'; column does not allow nulls. INSERT fails.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
.....
I am frighting with this problem more than 3 days. Can somebody help me to solve it?