Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate Saving a Collection via a StatelessSession
    text
    copied!<p>I have 2 classes that have a many-to-many collection of each other mapped within the class.</p> <p>Here is a simplified mapping of my two classes:</p> <p>Vehicle:</p> <pre><code>&lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"&gt; &lt;class xmlns="urn:nhibernate-mapping-2.2" name="EMTRAC.Devices.Device, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`Device`"&gt; &lt;id name="PK" type="System.Int64, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&gt; &lt;column name="PK" /&gt; &lt;generator class="identity" /&gt; &lt;/id&gt; &lt;version name="LastModifiedOn" column="LastModifiedOn" type="timestamp" access="field.pascalcase-underscore" /&gt; &lt;joined-subclass name="EMTRAC.Vehicles.Vehicle, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"&gt; &lt;key&gt; &lt;column name="Device_id" /&gt; &lt;/key&gt; &lt;component name="Zones" access="property"&gt; &lt;bag name="_list" cascade="save-update" access="field" table="VehicleZones" inverse="true"&gt; &lt;key&gt; &lt;column name="veh_id" not-null="true"/&gt; &lt;/key&gt; &lt;many-to-many class="EMTRAC.Zones.Zone, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/&gt; &lt;/bag&gt; &lt;/component&gt; &lt;property name="ID" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&gt; &lt;column name="ID" /&gt; &lt;/property&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>Zone:</p> <pre><code>&lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"&gt; &lt;class xmlns="urn:nhibernate-mapping-2.2" name="EMTRAC.Zones.Zone, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`Zone`"&gt; &lt;id name="ID" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&gt; &lt;column name="PK"/&gt; &lt;generator class="identity" /&gt; &lt;/id&gt; &lt;version name="LastModifiedOn" column="LastModifiedOn" type="timestamp" access="field.pascalcase-underscore" /&gt; &lt;property name="ID" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&gt; &lt;column name="ID" /&gt; &lt;/property&gt; &lt;component name="Vehicles" access="property"&gt; &lt;bag name="_list" cascade="save-update" access="field" table="VehicleZones"&gt; &lt;key&gt; &lt;column name="veh_id" not-null="true"/&gt; &lt;/key&gt; &lt;many-to-many class="EMTRAC.Vehicles.Vehicle, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/&gt; &lt;/bag&gt; &lt;/component&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>In my program I have 9600 Zones and 5000 Vehicles for my stress test of the system. Each Zone is currently mapped to each Vehicle and vice versa to mimic a "worse-case" scenario in the real world.</p> <p>I am needing to save this stress test data to the database and I am having several issues since the table that maps these two lists will be containing 48 million rows by the time it is said and done. In the real world the likelihood of saving all the items at once will be very minimal, but it still will occur. Therefore I need to be able to ensure that it will be possible to save this many items at any given time, even though I know this will take a substantial amount of time to do.</p> <p>I know that for batch processing a stateless session is recommended. However, I have read that stateless sessions ignore cascading updates, inheritance, and collections altogether. Saving the items with a stateless session is currently impossible as I receive stack overflow exceptions during the commit call.</p> <p>My question is this. If I save all the Zones and Vehicles first so the objects persist in the database. Is it possible to save the Lists via a stateless session and if so how would I go about doing so? If not are there any other recommendations? Everything I tried using a StatelessSession has resulted in no persister for Collection exception.</p> <p><em>EDIT</em> I've been tracing saving these objects using a regular session. If I break the saves into saving every 100 in a different session and transaction it is saving all the other properties of the Zone each time I call SaveOrUpdate on the Vehicle.</p> <p>Is there any way to get it to only save the List and not touch the Vehicle or Zone objects themselves? That would appear to be what I need to get this last piece working.</p>
 

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