-->
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: Manually specify the primary key value - problem
PostPosted: Tue Jan 05, 2010 6:10 am 
Newbie

Joined: Tue Jan 05, 2010 5:05 am
Posts: 1
Hello everyone,

I am trying to "insert" new record to the database using following code:

using System;
using Castle.ActiveRecord;
using System.Collections.Generic;

namespace TMS
{
[ActiveRecord("TMSConstructionSchema")]
public class TMSConstructionSchema
{
#region Private Members
private long _iSchemaID;
private string _description = string.Empty;
#endregion

#region Public Properties
[PrimaryKey(PrimaryKeyType.Assigned, "iSchemaID")]
public long SchemaID
{
get { return _iSchemaID; }
set { _iSchemaID = value; }
}

[Property("Description")]
public string Description
{
get { return _description; }
set { _description = value; }
}
#endregion
}
}

Everything seems to be ok with this code, but once I change the
[PrimaryKey(PrimaryKeyType.Assigned, "iSchemaID")]
attributes (PrimaryKeyType) to any other (native, customgenerator - either increment) I got the
following exception:

Unexpected row count: 0; expected: 1

I am using Save or Create (Create - first of all) method to "save" new data to the DB.
At the beginning of the project development the ID was defined as identity and everything worked fine
with [PrimaryKey("iSchemaID")] (I mean Save and Create).

Changing it to put some unique bigint value makes problems.

Reading from the DB works fine with any of PrimaryKeyType's.

What I am doing wrong?

_________________
www.jurasz.net


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.