Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate: Mapping multiple classes to the same view
    text
    copied!<p>I need to map two different classes to the same view and receive an error that a duplicate mapping exists. Is this possible in NHibernate? If not, can anyone give direction as to how I can solve this mapping problem.</p> <p>I work with views which are set in stone. One view brings back data needed to split into two classes. The view looks like:</p> <pre><code>vw_player_points ---------------- Id GameID PlayerID Points </code></pre> <p>The classes need to be 'player', with a list of games played</p> <pre><code>select gameid from vw_player_points where playerid = &lt;PlayerID&gt; </code></pre> <p>And each 'game' needs a list of players and their points:</p> <pre><code>select playerid, points from vw_player_points where gameid = &lt;GameID&gt; </code></pre> <p>I've tried table-per-concrete class inheritance aswell as mapping to the same view twice, but have had no joy :(</p> <p>Here's the 'rough' mappings put into one xml snippet. Notice I also need to map to an interface (which works)</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DomainModel" namespace="Test"&gt; &lt;class name="IPlayer" abstract="true"&gt; &lt;id name="Id" column="id"&gt; &lt;generator class="assigned"/&gt; &lt;/id&gt; &lt;union-subclass name="Player" table="vw_player"&gt; &lt;bag name="Games"&gt; &lt;key column="player_id"/&gt; &lt;one-to-many class="Test.IGame" not-found="ignore"/&gt; &lt;/bag&gt; &lt;/union-subclass&gt; &lt;/class&gt; &lt;class name="IGame" abstract="true"&gt; &lt;id name="Id" column="game_id"&gt; &lt;generator class="assigned"/&gt; &lt;/id&gt; &lt;union-subclass name="Game" table="vw_player_points"&gt; &lt;bag name="Points"&gt; &lt;key column="game_id"/&gt; &lt;one-to-many class="Test.IPlayerPoints" not-found="ignore"/&gt; &lt;/bag&gt; &lt;/union-subclass&gt; &lt;/class&gt; &lt;class name="IPlayerPoints" abstract="true"&gt; &lt;id name="Id" column="id"&gt; &lt;generator class="assigned"/&gt; &lt;/id&gt; &lt;union-subclass name="PlayerPoints" table="vw_player_points"&gt; &lt;property not-null="false" name="PlayerId" column="player_id"/&gt; &lt;property not-null="false" name="Points" column="points"/&gt; &lt;/union-subclass&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre>
 

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