I'm trying to map a List with an index column. This works fine, but i would also like to be able to query the index column from HQL. When i do that HQL throws an exception:
NHibernate.QueryException: could not resolve property: Position of: component[Location,Time]
To be able to query the WayPoint.Position column from HQL, i have created a Position-property in the WayPoint-class and i would like to map this property to the Position-column.
I have tried with:
wp.Map(x => x.Position).Column("Position");
But this results in a MappingException: NHibernate.MappingException: Repeated column in mapping for collection: Route.WayPoints column: Position
public class RouteMap : ClassMap<Route>
{
private const string LocationKey = "LocationIndex";
public RouteMap()
{
Not.LazyLoad();
ReadOnly();
Id(x => x.Id).GeneratedBy.Assigned();
Version(x => x.Version);
Map(x => x.Time);
References(x => x.StartingPoint).UniqueKey(LocationKey);
References(x => x.Destination).UniqueKey(LocationKey);
HasMany(x => x.WayPoints).Component( wp =>
{
wp.Map(x => x.Time);
//wp.Map(x => x.Position).Column("Position");
wp.Component( wp2 => wp2.Location, gl =>
{
gl.Map(x => x.Latitude);
gl.Map(x => x.Longitude);
}
);
}
).AsList(index => index.Column("Position")).Cascade.All();
}
}
create table `Route` (
Id VARCHAR(40) not null,
Version INTEGER not null,
Time BIGINT,
StartingPoint_id VARCHAR(40),
Destination_id VARCHAR(40),
primary key (Id),
unique (StartingPoint_id, Destination_id)
)
create table WayPoints (
Route_id VARCHAR(40) not null,
Latitude DOUBLE,
Longitude DOUBLE,
Time BIGINT,
Position INTEGER not null,
primary key (Route_id, Position)
)
Is it possible to map the Position property? Or is there another approach to make HQL aware of the Position-index-field? Thanks for the help!