I am facing one issue with one-to-many mapping with sequence.
one ----> Transactionheader
many ----->Transactionlines
During one of my transactions I will need to create new line item and add to Transactionlines.
mapping for transactionlines has configuration to take sequence id.
When I left the id for new line and assume hibernate would take care of that from sequence I got exception ,
(org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save():
I can set this id manually , the problem is it would not update the sequence associated with this table.
Here are my hbml.xmls,
for transactionheader,
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="Transactionheaders" table="transactionheaders" schema="public">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="assigned" />
</id>
<property name="store" type="java.lang.String">
<column name="store" length="3" />
</property>
<property name="date" type="java.util.Date">
<column name="date" length="29" />
</property>
<property name="ticketnumber" type="java.lang.String">
<column name="ticketnumber" length="6" />
</property>
<property name="ticketsequence" type="java.lang.String">
<column name="ticketsequence" length="3" />
</property>
<property name="custsalesrep" type="java.lang.String">
<column name="custsalesrep" length="10" />
</property>
<property name="ticketsalesrep" type="java.lang.String">
<column name="ticketsalesrep" length="10" />
</property>
<property name="salesrepused" type="java.lang.String">
<column name="salesrepused" length="10" />
</property>
<property name="customernumber" type="java.lang.String">
<column name="customernumber" length="12" />
</property>
<property name="customername" type="java.lang.String">
<column name="customername" length="25" />
</property>
<property name="headercommissionamt" type="java.lang.Double">
<column name="headercommissionamt" precision="17" scale="17" />
</property>
<set name="transactionlines" inverse="true" lazy="false" cascade="save-update">
<key>
<column name="hid" />
</key>
<one-to-many class="Transactionlines" />
</set>
</class>
</hibernate-mapping>
and for transactionlines,
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="Transactionlines" table="transactionlines" schema="public">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="assigned" />
</id>
<many-to-one name="transactionheaders" class="Transactionheaders" fetch="select">
<column name="hid" />
</many-to-one>
<property name="store" type="java.lang.String">
<column name="store" length="3" />
</property>
<property name="date" type="java.util.Date">
<column name="date" length="29" />
</property>
<property name="ticketnumber" type="java.lang.String">
<column name="ticketnumber" length="6" />
</property>
<property name="ticketsequence" type="java.lang.String">
<column name="ticketsequence" length="3" />
</property>
<property name="recordtype" type="java.lang.String">
<column name="recordtype" length="1" />
</property>
<property name="linenumber" type="java.lang.String">
<column name="linenumber" length="5" />
</property>
<property name="processdate" type="java.util.Date">
<column name="processdate" length="29" />
</property>
<property name="itemnumber" type="java.lang.String">
<column name="itemnumber" length="15" />
</property>
<property name="itemdescription1" type="java.lang.String">
<column name="itemdescription1" length="25" />
</property>
<property name="itemdescription2" type="java.lang.String">
<column name="itemdescription2" length="25" />
</property>
<property name="itemprimevendor" type="java.lang.String">
<column name="itemprimevendor" length="12" />
</property>
<property name="primevendorpart" type="java.lang.String">
<column name="primevendorpart" length="15" />
</property>
<property name="itemtype" type="java.lang.String">
<column name="itemtype" length="1" />
</property>
<property name="quantitysold" type="java.lang.Double">
<column name="quantitysold" precision="17" scale="17" />
</property>
<property name="unitofmeasure" type="java.lang.String">
<column name="unitofmeasure" length="5" />
</property>
<property name="linecost" type="java.lang.Double">
<column name="linecost" precision="17" scale="17" />
</property>
<property name="linestdcost" type="java.lang.Double">
<column name="linestdcost" precision="17" scale="17" />
</property>
<property name="linecostused" type="java.lang.Double">
<column name="linecostused" precision="17" scale="17" />
</property>
<property name="netlinesalesprice" type="java.lang.Double">
<column name="netlinesalesprice" precision="17" scale="17" />
</property>
<property name="priceoverridecode" type="java.lang.String">
<column name="priceoverridecode" length="1" />
</property>
<property name="commissioncalcmethod" type="java.lang.String">
<column name="commissioncalcmethod" length="1" />
</property>
<property name="linecommissionamount" type="java.lang.Double">
<column name="linecommissionamount" precision="17" scale="17" />
</property>
<property name="createdby" type="java.lang.String">
<column name="createdby" length="10" />
</property>
</class>
</hibernate-mapping>
Thanks
Sundar
|