-->
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.  [ 1 post ] 
Author Message
 Post subject: identity column+trigger returning null (nhibernate)
PostPosted: Tue Dec 18, 2007 7:25 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.  [ 1 post ] 

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.