Nibernate incomprehensible behavior











up vote
0
down vote

favorite












I am working on an old application using nhibernate 4.4.0400 to connect to oracle DB.



The save update command look like this:



CallContext.Session.Save(obj);  // Save or update the data record on database
transaction.Commit();
obj.MutCounter++;


Transaction created as follows:



  using (ITransaction transaction = CallContext.Session.BeginTransaction())
{...


Edit:
Method call is defined as this:



 public static void SaveOrUpdate(T obj)
{
if (obj == null)
throw new ArgumentNullException("obj");


Session is defined as follows:



public static ISession Session
{
get
{
if (HttpContext.Current == null)
throw new MissingHttpContextException();

if (HttpContext.Current.Items[HttpContextItemEnum.Session] == null)
HttpContext.Current.Items[HttpContextItemEnum.Session] = NHibernateHelper.OpenSession();

return HttpContext.Current.Items[HttpContextItemEnum.Session] as ISession;
}
set
{
if (HttpContext.Current == null)
throw new MissingHttpContextException();

HttpContext.Current.Items[HttpContextItemEnum.Session] = value;
}
}


On first call (click first time save button in the UI), I get the following exception:




Unique Constraint (...) verletzt



Could not synchronize database state with session




But if I click a second time right after (some seconds), the data are saved properly in the DB.



I don't know what is wrong, why I get this behavior, what I have to change to get a stabile behavior



Do you have any idea what to check? What to change? Why is this happening like this?










share|improve this question
























  • Why you are calling CallContext.Session.Save(obj);? Can you post a code few lines above it? How the obj is constructed?
    – Amit Joshi
    Nov 23 at 14:27










  • Hi Amit, the obj is given by the caller: See my Edit in the question. We ensure that the object exists. The object is an entity (Business object) and I checked that all mandatory data are set adequately.
    – DRK
    Nov 27 at 9:21












  • The CallContext.Session.Save refers to the NhibernateHelper which will do the saving.
    – DRK
    Nov 27 at 9:24















up vote
0
down vote

favorite












I am working on an old application using nhibernate 4.4.0400 to connect to oracle DB.



The save update command look like this:



CallContext.Session.Save(obj);  // Save or update the data record on database
transaction.Commit();
obj.MutCounter++;


Transaction created as follows:



  using (ITransaction transaction = CallContext.Session.BeginTransaction())
{...


Edit:
Method call is defined as this:



 public static void SaveOrUpdate(T obj)
{
if (obj == null)
throw new ArgumentNullException("obj");


Session is defined as follows:



public static ISession Session
{
get
{
if (HttpContext.Current == null)
throw new MissingHttpContextException();

if (HttpContext.Current.Items[HttpContextItemEnum.Session] == null)
HttpContext.Current.Items[HttpContextItemEnum.Session] = NHibernateHelper.OpenSession();

return HttpContext.Current.Items[HttpContextItemEnum.Session] as ISession;
}
set
{
if (HttpContext.Current == null)
throw new MissingHttpContextException();

HttpContext.Current.Items[HttpContextItemEnum.Session] = value;
}
}


On first call (click first time save button in the UI), I get the following exception:




Unique Constraint (...) verletzt



Could not synchronize database state with session




But if I click a second time right after (some seconds), the data are saved properly in the DB.



I don't know what is wrong, why I get this behavior, what I have to change to get a stabile behavior



Do you have any idea what to check? What to change? Why is this happening like this?










share|improve this question
























  • Why you are calling CallContext.Session.Save(obj);? Can you post a code few lines above it? How the obj is constructed?
    – Amit Joshi
    Nov 23 at 14:27










  • Hi Amit, the obj is given by the caller: See my Edit in the question. We ensure that the object exists. The object is an entity (Business object) and I checked that all mandatory data are set adequately.
    – DRK
    Nov 27 at 9:21












  • The CallContext.Session.Save refers to the NhibernateHelper which will do the saving.
    – DRK
    Nov 27 at 9:24













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am working on an old application using nhibernate 4.4.0400 to connect to oracle DB.



The save update command look like this:



CallContext.Session.Save(obj);  // Save or update the data record on database
transaction.Commit();
obj.MutCounter++;


Transaction created as follows:



  using (ITransaction transaction = CallContext.Session.BeginTransaction())
{...


Edit:
Method call is defined as this:



 public static void SaveOrUpdate(T obj)
{
if (obj == null)
throw new ArgumentNullException("obj");


Session is defined as follows:



public static ISession Session
{
get
{
if (HttpContext.Current == null)
throw new MissingHttpContextException();

if (HttpContext.Current.Items[HttpContextItemEnum.Session] == null)
HttpContext.Current.Items[HttpContextItemEnum.Session] = NHibernateHelper.OpenSession();

return HttpContext.Current.Items[HttpContextItemEnum.Session] as ISession;
}
set
{
if (HttpContext.Current == null)
throw new MissingHttpContextException();

HttpContext.Current.Items[HttpContextItemEnum.Session] = value;
}
}


On first call (click first time save button in the UI), I get the following exception:




Unique Constraint (...) verletzt



Could not synchronize database state with session




But if I click a second time right after (some seconds), the data are saved properly in the DB.



I don't know what is wrong, why I get this behavior, what I have to change to get a stabile behavior



Do you have any idea what to check? What to change? Why is this happening like this?










share|improve this question















I am working on an old application using nhibernate 4.4.0400 to connect to oracle DB.



The save update command look like this:



CallContext.Session.Save(obj);  // Save or update the data record on database
transaction.Commit();
obj.MutCounter++;


Transaction created as follows:



  using (ITransaction transaction = CallContext.Session.BeginTransaction())
{...


Edit:
Method call is defined as this:



 public static void SaveOrUpdate(T obj)
{
if (obj == null)
throw new ArgumentNullException("obj");


Session is defined as follows:



public static ISession Session
{
get
{
if (HttpContext.Current == null)
throw new MissingHttpContextException();

if (HttpContext.Current.Items[HttpContextItemEnum.Session] == null)
HttpContext.Current.Items[HttpContextItemEnum.Session] = NHibernateHelper.OpenSession();

return HttpContext.Current.Items[HttpContextItemEnum.Session] as ISession;
}
set
{
if (HttpContext.Current == null)
throw new MissingHttpContextException();

HttpContext.Current.Items[HttpContextItemEnum.Session] = value;
}
}


On first call (click first time save button in the UI), I get the following exception:




Unique Constraint (...) verletzt



Could not synchronize database state with session




But if I click a second time right after (some seconds), the data are saved properly in the DB.



I don't know what is wrong, why I get this behavior, what I have to change to get a stabile behavior



Do you have any idea what to check? What to change? Why is this happening like this?







c# oracle nhibernate transactions






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 27 at 9:23

























asked Nov 20 at 13:58









DRK

169214




169214












  • Why you are calling CallContext.Session.Save(obj);? Can you post a code few lines above it? How the obj is constructed?
    – Amit Joshi
    Nov 23 at 14:27










  • Hi Amit, the obj is given by the caller: See my Edit in the question. We ensure that the object exists. The object is an entity (Business object) and I checked that all mandatory data are set adequately.
    – DRK
    Nov 27 at 9:21












  • The CallContext.Session.Save refers to the NhibernateHelper which will do the saving.
    – DRK
    Nov 27 at 9:24


















  • Why you are calling CallContext.Session.Save(obj);? Can you post a code few lines above it? How the obj is constructed?
    – Amit Joshi
    Nov 23 at 14:27










  • Hi Amit, the obj is given by the caller: See my Edit in the question. We ensure that the object exists. The object is an entity (Business object) and I checked that all mandatory data are set adequately.
    – DRK
    Nov 27 at 9:21












  • The CallContext.Session.Save refers to the NhibernateHelper which will do the saving.
    – DRK
    Nov 27 at 9:24
















Why you are calling CallContext.Session.Save(obj);? Can you post a code few lines above it? How the obj is constructed?
– Amit Joshi
Nov 23 at 14:27




Why you are calling CallContext.Session.Save(obj);? Can you post a code few lines above it? How the obj is constructed?
– Amit Joshi
Nov 23 at 14:27












Hi Amit, the obj is given by the caller: See my Edit in the question. We ensure that the object exists. The object is an entity (Business object) and I checked that all mandatory data are set adequately.
– DRK
Nov 27 at 9:21






Hi Amit, the obj is given by the caller: See my Edit in the question. We ensure that the object exists. The object is an entity (Business object) and I checked that all mandatory data are set adequately.
– DRK
Nov 27 at 9:21














The CallContext.Session.Save refers to the NhibernateHelper which will do the saving.
– DRK
Nov 27 at 9:24




The CallContext.Session.Save refers to the NhibernateHelper which will do the saving.
– DRK
Nov 27 at 9:24

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394642%2fnibernate-incomprehensible-behavior%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394642%2fnibernate-incomprehensible-behavior%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen