Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate: how to map two columns for one table
    primarykey
    data
    text
    <p>I have a user table, that has 2 foreign keys for results (one for user result, and one for average result). There is one result table for both.</p> <p>How to map such situation in hibernate? I tried one-to-one mapping, but it don't work. In java, for easy access to results I want something like that:</p> <pre><code>public class ParticipantData { int id; DataValues pickedData; DataValues averageData; } </code></pre> <p>User table:</p> <pre><code>CREATE TABLE IF NOT EXISTS `participant_data` ( `participant_data_id` int(11) NOT NULL AUTO_INCREMENT, `picked_data_id` int(11) NOT NULL, `average_data_id` int(11) NOT NULL, PRIMARY KEY (`participant_data_id`), KEY `average_data` (`average_data_id`), KEY `picked_data` (`picked_data_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; </code></pre> <p>average_data and picked_data points to data_values_id in results</p> <p>Result table:</p> <pre><code>CREATE TABLE IF NOT EXISTS `data_values` ( `data_values_id` int(11) NOT NULL AUTO_INCREMENT, `n1` float NOT NULL, `s1` float NOT NULL, `x1` float NOT NULL, `a` float NOT NULL, `b` float NOT NULL, PRIMARY KEY (`data_values_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=36407 ; </code></pre> <p>My hibernate mapping that don't work:</p> <p>ParticipantData:</p> <pre><code>&lt;hibernate-mapping&gt; &lt;class name="com.mep.model.ParticipantData" table="participant_data"&gt; &lt;id name="id" type="int" column="participant_data_id" &gt; &lt;generator class="increment"/&gt; &lt;/id&gt; &lt;one-to-one name="pickedData" class="com.mep.model.DataValues" cascade="all" constrained="true"/&gt; &lt;one-to-one name="averageData" class="com.mep.model.DataValues" cascade="all" constrained="true"/&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>DataValues:</p> <pre><code>&lt;hibernate-mapping&gt; &lt;class name="com.mep.model.DataValues" table="data_values"&gt; &lt;id name="id" type="int" column="data_values_id"&gt; &lt;generator class="increment" /&gt; &lt;/id&gt; &lt;property name="n1" type="float" column="n1" /&gt; &lt;property name="s1" type="float" column="s1" /&gt; &lt;property name="x1" type="float" column="x1" /&gt; &lt;property name="a" type="float" column="a" /&gt; &lt;property name="b" type="float" column="b" /&gt; &lt;one-to-one name="participantData" class="com.mep.model.ParticipantData" cascade="all"&gt;&lt;/one-to-one&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>I will appreciate any help :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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