6

I am trying to use join to pull in a single property from another table, which doesn't have a mapping. My problem is that when I create a new instance of my mapped entity and save it I get an error about trying to insert into my unmapped table (it's trying to insert null into a not null column). I thought using .ReadOnly() would stop nhibernate from trying to insert into my unmapped table but that doesn't seem to work.

My mapping looks like this:

        // Join _UnMapped table with Mapped table to get the property
        Join("_UnMapped", x =>
            {
                x.Fetch.Join();
                x.KeyColumn("UnMappedFK");
                x.Map(y => y.Property, "Property")
                    .Not.Nullable()
                    .ReadOnly();
            });

I have thought about creating a view and mapping to that to get this property, but if I can I would rather do it through a mapping. Any help (or an explanation on how join is supposed to work) would be greatly appreciated!

Ben Tidman
  • 2,129
  • 17
  • 30

1 Answers1

8

Use x.Inverse();.

Here is some documentation about join.

cremor
  • 6,669
  • 1
  • 29
  • 72
  • As it turns out setting inverse worked after resolving some other issues I had. I don't entirely understand why though. I thought was just a flag to tell nhibernate which entity in the relationship owns the FK. in this case my mapped table is the one that has the FK (i.e. inverse = false right?). Your link doesn't work for me so unfortunately that doesn't help me. – Ben Tidman Jul 27 '11 at 14:30
  • @Ben Don't know why the link doesn't work for you, it works fine for me. But "inverse" is just a bad naming here. From the documentation: inverse (optional - defaults to false): If enabled, Hibernate will not try to insert or update the properties defined by this join. – cremor Jul 28 '11 at 05:30