First, I have the following table:
CREATE TABLE CustomerHub (
CustomerId INT NOT NULL,
HubId INT NOT NULL
)
Which I have mapped to the this entity:
public class CustomerHub
{
public int CustomerId {get;set;}
public int HubId {get;set}
//GetHashCode, Equals, Etc...
}
Using this mapping:
public class CustomerHubMap : ClassMap<CustomerHub>
{
UseCompositeId()
.WithKeyProperty(x => x.CustomerId)
.WithKeyProperty(x => x.HubId);
}
The problem I have is that when I create a new entity of type CustomerHub and attempt to save it, nothing is persisted to the database. I am able to retrieve everything fine, just not save them. For example:
//this will work
var x = session.CreateCriteria(typeof(CustomerHub));
//this will not
using (var trans = session.BeginTransaction())
{
var custHub = new CustomerHub {CustomerId = 293, HubId = 1193};
var y = session.SaveOrUpdate(custHub);
trans.Commit();
}
The odd part is that no exceptions are thrown, it simply just doesn't do anything. I fired up NH Profiler (excellent tool!) and it looks like it isn't issuing any type of insert command to the database.
Thoughts?
Note: I realize that this table looks much like a join table (because it technically is) and would best be served as a ManyToMany relationship on another entity such as Customer... but due to some extremely screwy data design (ie no Hub table) it is FAR simpler to map the join table to an entity and work with it that way.