C# NHibernate StaleObjectStateException
I have a MySQL database linked with NHibernate.
I am getting a StaleObjectStateException
:
Message : Test method DALTest.UnitTest1.AddingResultAndGetAll threw
exception: NHibernate.StaleObjectStateException: Row was updated or
deleted by another transaction (or unsaved-value mapping was
incorrect): [Domain.Bean.Result#3]
...here on the rr.Save call :
DateTime date = new DateTime();
rr = new ResultRepository();
FootRace foot = new FootRace(2,"une courseeee", "vraiment une chouette course", date, 5, false);
Participant part = new Participant(2,"Boveeé", "Joseeé", 123, "M", date, 5);
rr.Save(new Result(3,foot,part , new TimeSpan(2500),5));
Where my Interface implementation is :
public void Save(Result result) {
var e =Session.GetSessionImplementation().PersistenceContext.EntityEntries;
Session.SaveOrUpdate(result);
Session.Flush();
}
After doing some research it looks like it's a thread problem but I can't find a solution to this. By the way the database is resetted at the moment i call this test, so there is absolutely nothing inside.
Here is the XML mapping file:
<class name="Result" table="result">
<id name="Id" column="idResult" type="int">
<generator class="native"></generator>
</id>
<many-to-one name="FootRace" class="FootRace" column="idFootRace" cascade="save-update"/>
<many-to-one name="Participant" class ="Participant" column ="idParticipant" cascade="save-update"/>
<property name="RaceTime" column="raceTime" not-null="false"/>
<property name="Rank" column="rank"/>
</class>
c# hibernate exception
add a comment |
I have a MySQL database linked with NHibernate.
I am getting a StaleObjectStateException
:
Message : Test method DALTest.UnitTest1.AddingResultAndGetAll threw
exception: NHibernate.StaleObjectStateException: Row was updated or
deleted by another transaction (or unsaved-value mapping was
incorrect): [Domain.Bean.Result#3]
...here on the rr.Save call :
DateTime date = new DateTime();
rr = new ResultRepository();
FootRace foot = new FootRace(2,"une courseeee", "vraiment une chouette course", date, 5, false);
Participant part = new Participant(2,"Boveeé", "Joseeé", 123, "M", date, 5);
rr.Save(new Result(3,foot,part , new TimeSpan(2500),5));
Where my Interface implementation is :
public void Save(Result result) {
var e =Session.GetSessionImplementation().PersistenceContext.EntityEntries;
Session.SaveOrUpdate(result);
Session.Flush();
}
After doing some research it looks like it's a thread problem but I can't find a solution to this. By the way the database is resetted at the moment i call this test, so there is absolutely nothing inside.
Here is the XML mapping file:
<class name="Result" table="result">
<id name="Id" column="idResult" type="int">
<generator class="native"></generator>
</id>
<many-to-one name="FootRace" class="FootRace" column="idFootRace" cascade="save-update"/>
<many-to-one name="Participant" class ="Participant" column ="idParticipant" cascade="save-update"/>
<property name="RaceTime" column="raceTime" not-null="false"/>
<property name="Rank" column="rank"/>
</class>
c# hibernate exception
I forgot the xml mapping file :<class name="Result" table="result"> <id name="Id" column="idResult" type="int"> <generator class="native"></generator> </id> <many-to-one name="FootRace" class="FootRace" column="idFootRace" cascade="save-update"/> <many-to-one name="Participant" class ="Participant" column ="idParticipant" cascade="save-update"/> <property name="RaceTime" column="raceTime" not-null="false"/> <property name="Rank" column="rank"/> </class>
– Jules Civel
Nov 21 '18 at 21:14
edit your question and add the mapping
– live2
Nov 21 '18 at 21:16
Fixed up code tags, and added in the XML mapping file from the comments.
– e_i_pi
Nov 22 '18 at 0:31
@e_i_pi thanks for editing (and correcting) my post !
– Jules Civel
Nov 22 '18 at 16:03
Are you using identity columns in your database? I understand that thefoot
object andpart
doesn't exists and you want to create all 3 objects, right?
– Pablo Ferro
Nov 27 '18 at 18:37
add a comment |
I have a MySQL database linked with NHibernate.
I am getting a StaleObjectStateException
:
Message : Test method DALTest.UnitTest1.AddingResultAndGetAll threw
exception: NHibernate.StaleObjectStateException: Row was updated or
deleted by another transaction (or unsaved-value mapping was
incorrect): [Domain.Bean.Result#3]
...here on the rr.Save call :
DateTime date = new DateTime();
rr = new ResultRepository();
FootRace foot = new FootRace(2,"une courseeee", "vraiment une chouette course", date, 5, false);
Participant part = new Participant(2,"Boveeé", "Joseeé", 123, "M", date, 5);
rr.Save(new Result(3,foot,part , new TimeSpan(2500),5));
Where my Interface implementation is :
public void Save(Result result) {
var e =Session.GetSessionImplementation().PersistenceContext.EntityEntries;
Session.SaveOrUpdate(result);
Session.Flush();
}
After doing some research it looks like it's a thread problem but I can't find a solution to this. By the way the database is resetted at the moment i call this test, so there is absolutely nothing inside.
Here is the XML mapping file:
<class name="Result" table="result">
<id name="Id" column="idResult" type="int">
<generator class="native"></generator>
</id>
<many-to-one name="FootRace" class="FootRace" column="idFootRace" cascade="save-update"/>
<many-to-one name="Participant" class ="Participant" column ="idParticipant" cascade="save-update"/>
<property name="RaceTime" column="raceTime" not-null="false"/>
<property name="Rank" column="rank"/>
</class>
c# hibernate exception
I have a MySQL database linked with NHibernate.
I am getting a StaleObjectStateException
:
Message : Test method DALTest.UnitTest1.AddingResultAndGetAll threw
exception: NHibernate.StaleObjectStateException: Row was updated or
deleted by another transaction (or unsaved-value mapping was
incorrect): [Domain.Bean.Result#3]
...here on the rr.Save call :
DateTime date = new DateTime();
rr = new ResultRepository();
FootRace foot = new FootRace(2,"une courseeee", "vraiment une chouette course", date, 5, false);
Participant part = new Participant(2,"Boveeé", "Joseeé", 123, "M", date, 5);
rr.Save(new Result(3,foot,part , new TimeSpan(2500),5));
Where my Interface implementation is :
public void Save(Result result) {
var e =Session.GetSessionImplementation().PersistenceContext.EntityEntries;
Session.SaveOrUpdate(result);
Session.Flush();
}
After doing some research it looks like it's a thread problem but I can't find a solution to this. By the way the database is resetted at the moment i call this test, so there is absolutely nothing inside.
Here is the XML mapping file:
<class name="Result" table="result">
<id name="Id" column="idResult" type="int">
<generator class="native"></generator>
</id>
<many-to-one name="FootRace" class="FootRace" column="idFootRace" cascade="save-update"/>
<many-to-one name="Participant" class ="Participant" column ="idParticipant" cascade="save-update"/>
<property name="RaceTime" column="raceTime" not-null="false"/>
<property name="Rank" column="rank"/>
</class>
c# hibernate exception
c# hibernate exception
edited Nov 22 '18 at 0:31
e_i_pi
2,70921933
2,70921933
asked Nov 21 '18 at 21:13
Jules CivelJules Civel
11
11
I forgot the xml mapping file :<class name="Result" table="result"> <id name="Id" column="idResult" type="int"> <generator class="native"></generator> </id> <many-to-one name="FootRace" class="FootRace" column="idFootRace" cascade="save-update"/> <many-to-one name="Participant" class ="Participant" column ="idParticipant" cascade="save-update"/> <property name="RaceTime" column="raceTime" not-null="false"/> <property name="Rank" column="rank"/> </class>
– Jules Civel
Nov 21 '18 at 21:14
edit your question and add the mapping
– live2
Nov 21 '18 at 21:16
Fixed up code tags, and added in the XML mapping file from the comments.
– e_i_pi
Nov 22 '18 at 0:31
@e_i_pi thanks for editing (and correcting) my post !
– Jules Civel
Nov 22 '18 at 16:03
Are you using identity columns in your database? I understand that thefoot
object andpart
doesn't exists and you want to create all 3 objects, right?
– Pablo Ferro
Nov 27 '18 at 18:37
add a comment |
I forgot the xml mapping file :<class name="Result" table="result"> <id name="Id" column="idResult" type="int"> <generator class="native"></generator> </id> <many-to-one name="FootRace" class="FootRace" column="idFootRace" cascade="save-update"/> <many-to-one name="Participant" class ="Participant" column ="idParticipant" cascade="save-update"/> <property name="RaceTime" column="raceTime" not-null="false"/> <property name="Rank" column="rank"/> </class>
– Jules Civel
Nov 21 '18 at 21:14
edit your question and add the mapping
– live2
Nov 21 '18 at 21:16
Fixed up code tags, and added in the XML mapping file from the comments.
– e_i_pi
Nov 22 '18 at 0:31
@e_i_pi thanks for editing (and correcting) my post !
– Jules Civel
Nov 22 '18 at 16:03
Are you using identity columns in your database? I understand that thefoot
object andpart
doesn't exists and you want to create all 3 objects, right?
– Pablo Ferro
Nov 27 '18 at 18:37
I forgot the xml mapping file :
<class name="Result" table="result"> <id name="Id" column="idResult" type="int"> <generator class="native"></generator> </id> <many-to-one name="FootRace" class="FootRace" column="idFootRace" cascade="save-update"/> <many-to-one name="Participant" class ="Participant" column ="idParticipant" cascade="save-update"/> <property name="RaceTime" column="raceTime" not-null="false"/> <property name="Rank" column="rank"/> </class>
– Jules Civel
Nov 21 '18 at 21:14
I forgot the xml mapping file :
<class name="Result" table="result"> <id name="Id" column="idResult" type="int"> <generator class="native"></generator> </id> <many-to-one name="FootRace" class="FootRace" column="idFootRace" cascade="save-update"/> <many-to-one name="Participant" class ="Participant" column ="idParticipant" cascade="save-update"/> <property name="RaceTime" column="raceTime" not-null="false"/> <property name="Rank" column="rank"/> </class>
– Jules Civel
Nov 21 '18 at 21:14
edit your question and add the mapping
– live2
Nov 21 '18 at 21:16
edit your question and add the mapping
– live2
Nov 21 '18 at 21:16
Fixed up code tags, and added in the XML mapping file from the comments.
– e_i_pi
Nov 22 '18 at 0:31
Fixed up code tags, and added in the XML mapping file from the comments.
– e_i_pi
Nov 22 '18 at 0:31
@e_i_pi thanks for editing (and correcting) my post !
– Jules Civel
Nov 22 '18 at 16:03
@e_i_pi thanks for editing (and correcting) my post !
– Jules Civel
Nov 22 '18 at 16:03
Are you using identity columns in your database? I understand that the
foot
object and part
doesn't exists and you want to create all 3 objects, right?– Pablo Ferro
Nov 27 '18 at 18:37
Are you using identity columns in your database? I understand that the
foot
object and part
doesn't exists and you want to create all 3 objects, right?– Pablo Ferro
Nov 27 '18 at 18:37
add a comment |
0
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',
autoActivateHeartbeat: false,
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420549%2fc-sharp-nhibernate-staleobjectstateexception%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420549%2fc-sharp-nhibernate-staleobjectstateexception%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
I forgot the xml mapping file :
<class name="Result" table="result"> <id name="Id" column="idResult" type="int"> <generator class="native"></generator> </id> <many-to-one name="FootRace" class="FootRace" column="idFootRace" cascade="save-update"/> <many-to-one name="Participant" class ="Participant" column ="idParticipant" cascade="save-update"/> <property name="RaceTime" column="raceTime" not-null="false"/> <property name="Rank" column="rank"/> </class>
– Jules Civel
Nov 21 '18 at 21:14
edit your question and add the mapping
– live2
Nov 21 '18 at 21:16
Fixed up code tags, and added in the XML mapping file from the comments.
– e_i_pi
Nov 22 '18 at 0:31
@e_i_pi thanks for editing (and correcting) my post !
– Jules Civel
Nov 22 '18 at 16:03
Are you using identity columns in your database? I understand that the
foot
object andpart
doesn't exists and you want to create all 3 objects, right?– Pablo Ferro
Nov 27 '18 at 18:37