Hi, I'm having an issue with Hibernate 3.2.5, where I have to save only the parent object in a one-to-many relationship.
For example, I have a flower A, that can have many details. Firstly I want to save only the flower, and the details will be added later.
This process throws an exception:
not-null property references a null or transient value: com.juflora.bean.JFlora._floraSetBackref
This is my code:
JFlora flora = new JFlora();
flora.setTypeId(Integer.parseInt(type));
flora.setDescription(description);
flora.setName(name);
flora.setImage(image);
flora.setFloraDetails(new HashSet());
session.save(flora);
session.getTransaction().commit();
This is my mapping:
<?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">
<hibernate-mapping>
<class name="com.juflora.bean.JFlora" table="msflora">
<id column="floraid" name="floraId">
<generator class="increment"/>
</id>
<property column="floraname" name="name"/>
<property column="description" name="description"/>
<property column="image" name="image"/>
<property name="avgRating" formula="(SELECT IFNULL(AVG(r.rating), 0.0) FROM msrating r WHERE r.floraid = floraid)" update="false" insert="false"/>
<property name="rateCount" formula="(SELECT COUNT(*) FROM msrating r WHERE r.floraid = floraid)" update="false" insert="false"/>
<property name="sold" formula="(SELECT IFNULL(SUM(td.qty), 0) FROM mstransactiondetail td WHERE td.floraid=floraid AND (SELECT tr.status FROM mstransaction tr WHERE tr.transactionid=td.transactionid) LIKE 'Success')" update="false" insert="false"/>
<set cascade="all-delete-orphan" name="floraDetails" inverse="true" order-by="detailid">
<key column="floraid"/>
<one-to-many class="com.juflora.bean.JFloraDetail"/>
</set>
</class>
</hibernate-mapping>
Here is the stacktrace:
org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
com.juflora.doInsertFlora.processRequest(doInsertFlora.java:57)
com.juflora.doInsertFlora.doPost(doInsertFlora.java:104)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:574)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1527)
java.lang.Thread.run(Thread.java:595)