Note that there are some explanatory texts on larger screens.

plurals
  1. POMapping a property to an index column
    text
    copied!<p>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 <a href="http://en.wikipedia.org/wiki/Hibernate_%28Java%29#Hibernate_Query_Language_.28HQL.29" rel="nofollow noreferrer">HQL</a> throws an exception:</p> <blockquote> <p>NHibernate.QueryException: could not resolve property: Position of: component[Location,Time]</p> </blockquote> <p>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.</p> <p>I have tried with:</p> <pre><code>wp.Map(x =&gt; x.Position).Column("Position"); </code></pre> <p>But this results in a MappingException:</p> <blockquote> <p>NHibernate.MappingException: Repeated column in mapping for collection: Route.WayPoints column: Position</p> </blockquote> <pre><code>public class RouteMap : ClassMap&lt;Route&gt; { private const string LocationKey = "LocationIndex"; public RouteMap() { Not.LazyLoad(); ReadOnly(); Id(x =&gt; x.Id).GeneratedBy.Assigned(); Version(x =&gt; x.Version); Map(x =&gt; x.Time); References(x =&gt; x.StartingPoint).UniqueKey(LocationKey); References(x =&gt; x.Destination).UniqueKey(LocationKey); HasMany(x =&gt; x.WayPoints).Component( wp =&gt; { wp.Map(x =&gt; x.Time); //wp.Map(x =&gt; x.Position).Column("Position"); wp.Component( wp2 =&gt; wp2.Location, gl =&gt; { gl.Map(x =&gt; x.Latitude); gl.Map(x =&gt; x.Longitude); } ); } ).AsList(index =&gt; 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) ) </code></pre> <p>Is it possible to map the Position property? Or is there another approach to make HQL aware of the Position-index-field?</p> <hr>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload