Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate: getting not-null property references a null or transient value
    primarykey
    data
    text
    <p>I am new to Hibernate. I have two classes "quotation" and "quotation_item" their database structure is like this</p> <pre><code>create table quotation ( quotation_id int primary key auto_increment, code varchar(20), client_name varchar(20) ); create table quotation_item ( id int primary key auto_increment, quotation_id int, item_name varchar(20), rate int, qty int, FOREIGN KEY (quotation_id) REFERENCES quotation(quotation_id) ); </code></pre> <p>Quotation.hbm.xml is like this, <code></p> <pre><code> &lt;hibernate-mapping&gt; &lt;class name="com.paramatrix.pojo.Quotation" table="quotation"&gt; &lt;id name="quotationId" type="int" column="quotation_id"&gt; &lt;generator class="native" /&gt; &lt;/id&gt; &lt;property name="code" column="code" type="string" /&gt; &lt;property name="clientName" column="client_name" type="string" /&gt; &lt;set name="quotationItem" table="quotation_item" fetch="select" cascade="all"&gt; &lt;key&gt; &lt;column name="quotation_id" not-null="true" /&gt; &lt;/key&gt; &lt;one-to-many class="com.paramatrix.pojo.QuotationItem" /&gt; &lt;/set&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>QuotationItem.hbm.xml is like this,</p> <pre><code>&lt;hibernate-mapping&gt; &lt;class name="com.paramatrix.pojo.QuotationItem" table="quotation_item"&gt; &lt;id name="id" type="int" column="id"&gt; &lt;generator class="native" /&gt; &lt;/id&gt; &lt;many-to-one name="quotation" class="com.paramatrix.pojo.Quotation" cascade="save-update"&gt; &lt;column name="quotation_id" not-null="true" /&gt; &lt;/many-to-one&gt; &lt;property name="itemName" column="item_name" type="string" /&gt; &lt;property name="rate" column="rate" type="int" /&gt; &lt;property name="qty" column="qty" type="int" /&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p></code></p> <p>POJO's are 1>Quotation.java</p> <pre><code>public class Quotation { int quotationId; String code; String clientName; Set&lt;QuotationItem&gt; quotationItem=new HashSet&lt;QuotationItem&gt;(); //getter&amp; setter } </code></pre> <p>2>QuotationItem.java</p> <pre><code>public class QuotationItem{ int id; Quotation quotation; String itemName; int rate; int qty; //getter and setter } </code></pre> <p>main method is </p> <pre><code>Set&lt;QuotationItem&gt; set=new HashSet&lt;QuotationItem&gt;(); SessionFactory factory = new Configuration().configure().buildSessionFactory(); Session session=factory.openSession(); session.beginTransaction(); Quotation quotation = new Quotation(); quotation.setCode(txtCode.getValue()); quotation.setClientName(txtClientName.getValue()); QuotationItem quotationItem = new QuotationItem(); quotationItem.setItemName(txtItemName.getValue()); quotationItem.setQty(Integer.parseInt( txtQty.getValue())); quotationItem.setRate(Integer.parseInt(txtRate.getValue())); set.add(quotationItem); quotation.setQuotationItem(set); session.saveOrUpdate((quotation)); session.getTransaction().commit(); System.out.println("Done"); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload