To be more precise, it cannot work with an NHibernate-assigned ID value. You
can let NHibernate populate the an association table with surrogate key
automatically, but this works only with a key that can be assigned by the DB
(Identity, rowid() etc.) when all other attributes are nullable (they will
be null by default).

-Markus

2009/8/3 Markus Zywitza <[email protected]>

> You have to create the TransactionGroupUser object explicitly.
>
> -Markus
>
> 2009/8/3 William Chang <[email protected]>
>
>
>> I'm having trouble with using many-to-many relation,
>> "HasAndBelongsToMany" attribute. I read the section titled
>> "Association table with surrogate key" in the documentation and does
>> not extend on using with "Create()":
>>
>> http://www.castleproject.org/activerecord/documentation/trunk/usersguide/relations/hasandbelongs.html
>>
>> I do not know if I should create the object from the association table
>> or not? I tried creating an object from one of the foreign tables, but
>> I got an error:
>>
>>  ----> NHibernate.Exceptions.GenericADOException : could not insert
>> collection:
>>
>> [Testsoft.Data.Models.Transaction.transactionGroups#43fc1ed4-3919-4d12-989b-9c590167bb15]
>> [SQL: INSERT INTO TransactionsGroupsUsers (entityTransactionId,
>> entityGroupId) VALUES (?p0, ?p1)]
>>  ----> MySql.Data.MySqlClient.MySqlException : Duplicate entry '' for
>> key 1
>>
>> About my association table, I have three tables connecting to it by
>> foreign key: Transactions, Groups, and Users. I found that the
>> surrogate key is not being generating by ActiveRecord when using
>> "Create()" method. The surrogate key column ends up being blank after
>> INSERT.
>>
>> Test Code Snippet:
>>        IList<Data.Models.Group> gs1 = new List<Data.Models.Group>();
>>        gs1.Add(g1);
>>
>>        IList<Data.Models.User> us1 = new List<Data.Models.User>();
>>        us1.Add(u1);
>>
>>        Models.Transaction t1 = new Models.Transaction() {
>>            transactionType =
>> Testsoft.Data.Models.Transaction.enumType.Requisition,
>>            transactionCreator = requisition.requisitionCreator,
>>            transactionRequisition = requisition,
>>            transactionGroups = gs1,
>>            transactionUsers = us1,
>>            transactionDateCreated = DateTime.Now
>>        };
>>
>>        t1.Create();
>>
>> Source Code Snippet:
>> public class TransactionGroupUser :
>> ActiveRecordBase<TransactionGroupUser> {
>>    [PrimaryKey(PrimaryKeyType.GuidComb)]
>>    public virtual Guid entityId {get;set;}
>>    [BelongsTo("entityTransactionId")]
>>    public virtual Transaction entityTransaction {get;set;}
>>    [BelongsTo("entityGroupId")]
>>    public virtual Group entityGroup {get;set;}
>>    [BelongsTo("entityUserId")]
>>    public virtual User entityUser {get;set;}
>> }
>>
>> Specs:
>> Microsoft ASPNET 3.5
>> MySQL 5.0.24a
>> MySQL Connector/Net 6.1.0
>> NHibernate 2.1.0GA
>> Castle ActiveRecord 2.0
>>
>> Please help?
>>
>> Thank you,
>> William Chang
>> >>
>>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to