c# - How to save a large nhibernate collection without causing OutOfMemoryException -


How can a large collection with NHibernate be saved, in which there are elements that exceed the amount of approved memory for the process?

>

I am trying to save a video object with nhibernate which contains a large number of screenshots (code See below). Each screenshot has a byte [], so after nhibernate try to save 10,000 or so records at a time, an out-of-the-mortgage opsion is thrown. Normally I try to save and flush the session after every 500 or so record, but in this case, I need to save the archive because it automatically saves the sock order and video id for me (screenshot Without knowing it was part of a video) What is the best way to conform to my situation? What is a way to save screenshots without having to know about your original video?

For your reference, here is a simple sample code I created:

  Public class video {public long ID} (get; set;} public string name { Get; set;} public video () {screenshot = new arrelist ();} public IList screenshots {get; set;}} public class screenshot {public long id {receiving; set;} public byte [] data {get; set ;}}  

and mapping:

  & lt ;? xml session HTML = "1.0" encoding = "UTF-8"? & Gt; Hibernate-Mapping XMLNS = "Color: Nibinet-Mapping -2.2" assembly = "savingSystemsTestrail" Namespace = "savingscentheath" default "access =" property " & Lt; class name = "screenshot" lazy = "false" & gt; id = "id" type = "int64"> gt; generator class = "move" / " Gt; & lt; / id & gt; Property Name = "Data" column = "data" type = "binaryblock" length = "2147483647" no-null = "true" /> gt; & lt; / square & Gt; & Lt ; / Hibernate-mapping & gt; & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Hibernate-Mapping xmlns = "UV: Nibinet-Mapping -2.2" Assembly = "Savings Screenshots Trial" Namespace = "SavingsSenshots Trial" & gt; & Lt; Class name = "video" lazy = "false" table = "video" discriminator-value = "0" abstract = "true" & gt; & Lt; Id name = "id" type = "int64" access = "property" & gt; & Lt; Generator class = "hilo" /> & Lt; / Id & gt; & Lt; Property Name = "Name" /> & Lt; List name = "screenshots" cascade = "all-delete-orphan" lazy = "false" & gt; & Lt; Major column = "VideoEd" /> & Lt; Index column = "sort order" /> & Lt; One-to-many classes = "screenshots" /> & Lt; / List & gt; & Lt; / Square & gt; & Lt; / Hibernate-mapping & gt;  

When I try to save the video with 10000 screenshots, it throws an outfammy exception. Here is the code I am using:

 using  (var session = CreateSession ()) {video video = new video (); {Video.Screenshots.Add (new screenshot ()} {data = camera. Lefscrash (resolution)} for (Int i = 0; I & lt; 10000; i ++); } Session.SaveOrUpdate (video); } 

For this reason, we usually have a child's unit Rather than references from the opposite.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -