-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: Newbie Nullables concurrency checking question
PostPosted: Fri Jan 12, 2007 3:02 pm 
Newbie

Joined: Fri Jan 12, 2007 2:28 pm
Posts: 10
Location: Houston, TX
Hello,

I am using VB.NET w/ .NET 1.1 and MSSQL 2000 and NHibernate 1.0.3. I'm trying to cope with columns that allow nulls, in my particular case it's an integer column. It's defined in my .hbm.xml file like this:

Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="NHibernateTest.NHibernateTestClass, NHibernateTest" dynamic-update="true" table="NHibernateTestTable" optimistic-lock="dirty">
    <id name="Seq" type="Int32">
      <generator class="identity" />
    </id>
    <property name="NullableInt" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" not-null="false" />
  </class>
</hibernate-mapping>


In my VB.NET class the property is defined as:

Code:
Private _NullableInt As Nullables.NullableInt32
Public Property NullableInt() As Nullables.NullableInt32
    Get
        Return _NullableInt
    End Get
    Set(ByVal Value As Nullables.NullableInt32)
        _NullableInt = Value
    End Set
End Property


I have inserted one row into this table, which contains a NULL in the NullableInt column. It loads my one entry from the database table just fine, then I set the value of the NULL property to 0:

Code:
Dim test As NHibernateTestClass = CType(session.Load(GetType(NHibernateTestClass), 1), NHibernateTestClass)
Debug.Assert(Not test.NullableInt.HasValue)
test.NullableInt = New Nullables.NullableInt32(0)
Debug.Assert(test.NullableInt.HasValue)
session.Flush()


... but after I flush the session, I see the following generated SQL:

Code:
NHibernate: UPDATE NHibernateTestTable SET NullableInt = @p0 WHERE Seq = @p1 AND NullableInt=@p2
@p0 = '0'
@p1 = '1'
@p2 = ''


This fails - because it should be testing in the WHERE clause that "NullableInt IS NULL" - right?

Then the exception occurs:

Code:
An unhandled exception of type 'NHibernate.HibernateException' occurred in nhibernate.dll

Additional information: SQL insert, update or delete failed (expected affected row count: 1, actual affected row count: 0). Possible causes: the row was modified or deleted by another user, or a trigger is reporting misleading row count.


I understand why the exception is occuring, it just doesn't make any sense to my what the generated UPDATE statement is not looking like what I expect. Can anyone tell me what I should do or look at in order to investigate this?

Thanks!
David McClelland


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 12, 2007 7:49 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
This does look like a bug in the nullables library, or maybe in NH itself, I am not sure.
Please open a JIRA with a test case.

At any rate, this looks like you are using full optimistic concurrency, can you use <version> instead?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 14, 2007 7:04 am 
Newbie

Joined: Wed Nov 08, 2006 7:55 am
Posts: 4
There are two ways to resolve your problem:

one:
in your class define, change .net data type to NHibernate date type,
example:

NHibernateUtil.int32 year;


two:

set the default: example:
int year=2007;


other,like string ,datetime,long etc ,you must do like up,too.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 14, 2007 7:06 am 
Newbie

Joined: Wed Nov 08, 2006 7:55 am
Posts: 4
There are two ways to resolve your problem:

one:
in your class define, change .net data type to NHibernate date type,
example:

NHibernateUtil.int32 year;


two:

set the default: example:
int year=2007;


other,like string ,datetime,long etc ,you must do like this,too.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 15, 2007 12:29 pm 
Newbie

Joined: Fri Jan 12, 2007 2:28 pm
Posts: 10
Location: Houston, TX
Ayende Rahien wrote:
This does look like a bug in the nullables library, or maybe in NH itself, I am not sure.
Please open a JIRA with a test case.

At any rate, this looks like you are using full optimistic concurrency, can you use <version> instead?


FYI, I just finished testing this with 1.2 beta 3, and same thing occurs:

Code:
NHibernate: UPDATE NHibernateTestTable SET NullableInt = @p0 WHERE Seq = @p1 AND NullableInt=@p2; @p0 = '0', @p1 = '1', @p2 = ''
NHibernate.StaleStateException: Unexpected row count: 0; expected: 1


I will open up a JIRA issue with a test case. I would love to be using <version> instead, but for now I cannot change the database schema to add any columns.

I really really really wish this worked, so that I could use NHibernate! Of course I also wish that we were using .NET Framework 2.0 so that we'd have built-in nullable types :-)

- David McClelland


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 15, 2007 12:42 pm 
Newbie

Joined: Fri Jan 12, 2007 2:28 pm
Posts: 10
Location: Houston, TX
zhoutao wrote:
There are two ways to resolve your problem:

one:
in your class define, change .net data type to NHibernate date type,
example:

NHibernateUtil.int32 year;


two:

set the default: example:
int year=2007;


other,like string ,datetime,long etc ,you must do like this,too.



If you take another look at the VB.NET code that I listed above, you'll see that I'm using the NullableInt32 datatype in my class, not the built-in datatype.

Also, I don't understand why you are referring to NHibernateUtil.Int32 - this isn't a datatype, it's an instance of NHibernate.Type.NullableType.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 15, 2007 1:42 pm 
Newbie

Joined: Fri Jan 12, 2007 2:28 pm
Posts: 10
Location: Houston, TX
This has been submitted as JIRA issue NH-864.


Top
 Profile  
 
 Post subject: Fixed!
PostPosted: Mon Feb 26, 2007 9:20 am 
Newbie

Joined: Fri Jan 12, 2007 2:28 pm
Posts: 10
Location: Houston, TX
drmcclelland wrote:
This has been submitted as JIRA issue NH-864.


The fix looks great in 1.2.0 CR1, thanks Ayende & Sergey!


Top
 Profile  
 
 Post subject: identity column+trigger returning null (nhibernate)
PostPosted: Tue Dec 18, 2007 7:23 am 
Newbie

Joined: Tue Dec 18, 2007 7:11 am
Posts: 7
I am using C#.NET w/ .NET 2.0 and MSSQL 2000 and NHibernate 1.0.3. I'm trying to insert a row in table which is having instead of insert trigger on it. It's defined in my .hbm.xml file like this:

[code<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="ECM.Domain" namespace="ECM.Domain" >
<class name="Employee" table="Employee" >
<id name="Id" column="EMPLOYEE_ID" type="Int32" unsaved-value="0">
<generator class="identity"/>
</id>
<property name="Name" column="NAME" type="String" length="100" not-null="true" />
</class>
</hibernate-mapping>

public class Employee
{

private int id;

public int Id
{
get { return id; }
set { id = value; }
}

private String name;

public String Name
{
get { return name; }
set { name = value; }
}

}


CODE:

sessionFactory = new NHibernate.Cfg.Configuration().Configure().BuildSessionFactory();

ISession dataSession;
Employee EmployeeItem = null;
try
{
dataSession = sessionFactory.OpenSession();
EmployeeItem = (Employee)dataSession.CreateCriteria(typeof(Employee))
.Add(Expression.Eq(id, Name)).UniqueResult();

if (EmployeeItem != null)
return 2;

EmployeeItem = new Employee();
EmployeeItem.Name = Name;

tx = dataSession.BeginTransaction();
dataSession.Save(EmployeeItem);
tx.Commit();

while saving it is giving DBnull cannot be changed to Int32,64
I debugged and tried while inserting query generated is like this
Select SCOPE_IDENTITY(); it returns null since a trigger is there and
the sope of query is over.

if we use @@identity it will return identity even sope of query is over.
can we generate @@identity through nhibernate.

is there any way i can get identity even trigger is there .

_________________
venkat


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.