{"id":49,"date":"2009-02-26T17:42:00","date_gmt":"1970-01-01T00:00:00","guid":{"rendered":"http:\/\/www.yazilimmutfagi.com\/?p=49"},"modified":"2009-02-26T17:42:00","modified_gmt":"1970-01-01T00:00:00","slug":"nhibernate-could-not-initialize-proxy-the-owning-session-was-closed-hatasi","status":"publish","type":"post","link":"https:\/\/www.yazilimmutfagi.com\/index.php\/2009\/02\/26\/nhibernate-could-not-initialize-proxy-the-owning-session-was-closed-hatasi\/","title":{"rendered":"NHibernate \u201cCould not initialize proxy &#8211; the owning Session was closed\u201d Hatasi"},"content":{"rendered":"<p style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\" class=\"MsoNormal\"><strong style=\"\"><span style=\"font-size: 12pt; line-height: 115%;\"><span style=\"font-family: Calibri;\">NHibernate &ldquo;Could not initialize proxy &#8211; the owning Session was closed&rdquo; Hatasi<\/span><\/span><\/strong><\/p>\n<p style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\" class=\"MsoNormal\"><span style=\"font-size: small; font-family: Calibri;\">Nhibernate ile &ccedil;alisiyorsunuz ve iliskilerle dolu bir veritabaniniz var. Kodunuzu yazarken haliyle nhibernate in size sagladigi avantajlari kullanmak istiyorsunuz ve classlarinizdan birinden t&uuml;rettiginiz bir nesnenizin iliskili oldugu nesnelere ulasmaya &ccedil;alisiyorsunuz. Bu durumda alacaginiz hata baslikta da ge&ccedil;en <strong style=\"\">&ldquo;Could not initialize proxy &#8211; the owning Session was closed&rdquo; <\/strong>hatasi olabilir.<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\" class=\"MsoNormal\"><span style=\"font-size: small; font-family: Calibri;\">Ogrenci ve Sinif adli iki classimiz ve Ogrenci classinda Sinif classina iliski oldugunu varsayalim. Ve bir &ouml;grencinin sinifinin adi bilgisine ulasmaya &ccedil;alisalim.<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: rgb(43, 145, 175); font-family: &quot;Courier New&quot;;\">Ogrenci<\/span><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"> ogrenci1 = getOgrenci(ogrenciNo);<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; line-height: 115%; font-family: &quot;Courier New&quot;;\">Label1.Text = ogrenci1.Sinifi.SinifAdi;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt; text-indent: 18pt;\" class=\"MsoNormal\"><a href='www.yazilimmutfagi.com'>.<\/a><\/p>\n<p style=\"margin: 0cm 0cm 10pt; text-indent: 18pt;\" class=\"MsoNormal\"><span style=\"font-size: small; font-family: Calibri;\">Standart yollarla olusturulmus class ve mapping dosyalarinizla bu durumda hata almaniz muhtemel. Ve bu sorunu 2 yolla asabilirsiniz. <\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 36pt; text-indent: -18pt;\" class=\"MsoListParagraphCxSpFirst\"><span style=\"\"><span style=\"\"><span style=\"font-size: small; font-family: Calibri;\">1.<\/span><span style=\"font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span style=\"font-size: small; font-family: Calibri;\">GetOgrenci() fonksiyonuna su eki yaparak:<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 36pt;\" class=\"MsoListParagraphCxSpMiddle\"><span style=\"font-size: small; font-family: Calibri;\">&nbsp;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 36pt; line-height: normal;\" class=\"MsoListParagraphCxSpMiddle\"><span style=\"font-size: 10pt; color: rgb(43, 145, 175); font-family: &quot;Courier New&quot;;\">ISession<\/span><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"> s = <span style=\"color: rgb(43, 145, 175);\">HibernateSession<\/span>.GetSession();<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 36pt; line-height: normal;\" class=\"MsoListParagraphCxSpMiddle\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\">&nbsp;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 36pt; line-height: normal;\" class=\"MsoListParagraphCxSpMiddle\"><span style=\"font-size: 10pt; color: rgb(43, 145, 175); font-family: &quot;Courier New&quot;;\">ICriteria<\/span><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"> kriter = s.CreateCriteria(<span style=\"color: blue;\">typeof<\/span>(<span style=\"color: rgb(43, 145, 175);\">Ogrenci<\/span>));<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 36pt; line-height: normal;\" class=\"MsoListParagraphCxSpMiddle\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\">&nbsp;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 36pt; line-height: normal;\" class=\"MsoListParagraphCxSpMiddle\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\">kriter.Add(<span style=\"color: blue;\">new<\/span> <span style=\"color: rgb(43, 145, 175);\">EqExpression<\/span>(<span style=\"color: rgb(163, 21, 21);\">&quot;OgrenciNo&quot;<\/span>, ogrenciNo));<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 36pt; line-height: normal;\" class=\"MsoListParagraphCxSpMiddle\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\">&nbsp;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 36pt; line-height: normal;\" class=\"MsoListParagraphCxSpMiddle\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\">kriter.SetFetchMode(<span style=\"color: rgb(163, 21, 21);\">&quot;Sinifi&quot;<\/span>, <span style=\"color: rgb(43, 145, 175);\">FetchMode<\/span>.Join);<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 36pt;\" class=\"MsoListParagraphCxSpMiddle\"><span style=\"font-size: small; font-family: Calibri;\">&nbsp;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt 36pt; text-indent: -18pt;\" class=\"MsoListParagraphCxSpLast\"><span style=\"\"><span style=\"\"><span style=\"font-size: small; font-family: Calibri;\">2.<\/span><span style=\"font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span style=\"font-size: small; font-family: Calibri;\">Ya da Ogrenci mapping dosyaniza su eki yaparak:<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: blue; line-height: 115%; font-family: &quot;Courier New&quot;;\">&lt;<\/span><span style=\"font-size: 10pt; color: rgb(163, 21, 21); line-height: 115%; font-family: &quot;Courier New&quot;;\">many-to-one<\/span><span style=\"font-size: 10pt; color: blue; line-height: 115%; font-family: &quot;Courier New&quot;;\"> <\/span><span style=\"font-size: 10pt; color: red; line-height: 115%; font-family: &quot;Courier New&quot;;\">name<\/span><span style=\"font-size: 10pt; color: blue; line-height: 115%; font-family: &quot;Courier New&quot;;\">=<\/span><span style=\"font-size: 10pt; line-height: 115%; font-family: &quot;Courier New&quot;;\">&quot;<span style=\"color: blue;\">Sinif<\/span>&quot;<span style=\"color: blue;\"> <\/span><span style=\"color: red;\">column<\/span><span style=\"color: blue;\">=<\/span>&quot;<span style=\"color: blue;\">Sinif<\/span>&quot;<span style=\"color: blue;\"> <\/span><span style=\"color: red;\">class<\/span><span style=\"color: blue;\">=<\/span>&quot;<span style=\"color: blue;\">Sinif<\/span>&quot;<span style=\"color: blue;\"> <\/span><span style=\"color: red;\">fetch<\/span><span style=\"color: blue;\">=<\/span>&quot;<span style=\"color: blue;\">join<\/span>&quot;<span style=\"color: blue;\"> \/&gt;<\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\" class=\"MsoNormal\"><span style=\"font-size: small; font-family: Calibri;\">Peki, Sinif classinin Ogretmen classiyla SinifOgretmeni alani &uuml;zerinden iliskili oldugunu ve bizim su sekilde bu alana ulasmak istedigimizi d&uuml;s&uuml;nelim:<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: rgb(43, 145, 175); line-height: 115%; font-family: &quot;Courier New&quot;;\">Ogrenci<\/span><span style=\"font-size: 10pt; line-height: 115%; font-family: &quot;Courier New&quot;;\"> ogrenci1 = getOgrenci(ogrenciNo);<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; line-height: 115%; font-family: &quot;Courier New&quot;;\">Label1.Text = ogrenci1.Sinifi.SinifAdi;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; line-height: 115%; font-family: &quot;Courier New&quot;;\">Label2.Text = ogrenci1.Sinifi.SinifOgretmeni.Adi;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\" class=\"MsoNormal\"><span style=\"font-size: small; font-family: Calibri;\">Ilk y&ouml;ntemi kullandiginiz takdirde burada yine ayni hataya d&uuml;seceksiniz. Ancak 2. y&ouml;ntem sorunu asmaniza yardimci olacaktir.<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\" class=\"MsoNormal\"><span style=\"font-size: small; font-family: Calibri;\">Eklemek istedigim son nokta, bu t&uuml;r kullanimlarla nhibernate in ilgili t&uuml;m verileri &ccedil;ektigini ve veri yogunlugunun ve performans ihtiyacinin g&ouml;z &ouml;n&uuml;nde tutularak bu y&ouml;ntemlerin kullanilmasi gerektigidir. <\/span><\/p>","protected":false},"excerpt":{"rendered":"<p>Nhibernate ile &#231;alisiyorsunuz ve iliskilerle dolu bir veritabaniniz var. Kodunuzu yazarken haliyle nhibernate in size sagladigi avantajlari kullanmak istiyorsunuz ve classlarinizdan birinden t&#252;rettiginiz bir nesnenizin iliskili oldugu nesnelere ulasmaya &#231;alisiyorsunuz. Bu durumda alacaginiz hata bas<\/p>\n","protected":false},"author":538,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[433],"tags":[4493,4282,5031],"_links":{"self":[{"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/posts\/49"}],"collection":[{"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/users\/538"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/comments?post=49"}],"version-history":[{"count":0,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/posts\/49\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/media?parent=49"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/categories?post=49"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/tags?post=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}