-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mapping issues with SubclassAttribute
#14
Comments
NHibernate.Mapping.Attributes.SubclassAttribute
SubclassAttribute
Ideally, you should use But maybe you want to use this hybrid mapping, which requires to use
From the code samples in the project, it seems the correct way is this (notice the additional ordering): [Subclass(DiscriminatorValue = "data_api", ExtendsType = typeof(BaseResource), Lazy = true)]
public class DataApi : BaseResource {
[Join(0, Schema = "public", Table = "data_apis", Fetch = JoinFetch.Select)]
[Key(1, Column = "id")]
[Property(2, Name = nameof(Statement), Column = "statement", Length = 128, NotNull = true)]
[Property(3, Name = nameof(Parameters), Column = "parameters", Length = 128, NotNull = true)]
[ManyToOne(4, Name = "DataSource", Column = "data_source_id", ClassType = typeof(DataSource), NotFound = NotFoundMode.Ignore, Lazy = Laziness.Proxy, Fetch = FetchMode.Select)]
public virtual string Statement { get; set; }
public virtual string Parameters { get; set; }
public virtual DataSource DataSource { get; set; }
} As stated in the documentation:
That is the "magic". Unless using a component for grouping the properties of the join, or a [RawXml] mapping of the join, I do not think there is any other way to group many properties in the same join. (I do not think duplicating the |
Adding order is better, but it's not obligatory, and the Thanks for the detailed explaination, I know the But this time I just want to try hybrid mapping with Anyway, both |
I have found some issues when using
SubclassAttribute
with attribute mapping, for example, the base class is:The generated xml mapping is correct :
And I have a sub class which is:
This looks correct, but the xml mapping generated is not correct:
Then I change the code for
DataApi
, move all of thePropertyAttribute
to one property, like this:Then the xml mapping generated is corrected now, looks like:
But is the sub class
DataApi
has amany-to-one
mapping like this:The xml mapping generated is not correct again, like this:
There is only one
many-to-one
element , other properties is not generated.But if I move the
ManyToOne
afterProperty
, like this:Then the xml mapping generated is correct again, like this:
I think that's very strange behavior,is there any who can tell me the magic?
And I think
SubclassAttribute
should be used the same way asClassAttribute
, like this:Is anyone who can improve it?
The text was updated successfully, but these errors were encountered: