我有一个用户表,它有 2 个用于结果的外键(一个用于用户结果,一个用于平均结果)。两者都有一个结果表。
如何在休眠中映射这种情况?我尝试了一对一的映射,但它不起作用。在java中,为了方便访问结果,我想要这样的东西:
public class ParticipantData {
int id;
DataValues pickedData;
DataValues averageData;
}
用户表:
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 ;
average_data 和pick_data 指向结果中的data_values_id
结果表:
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 ;
我的休眠映射不起作用:
参与者资料:
<hibernate-mapping>
<class name="com.mep.model.ParticipantData" table="participant_data">
<id name="id" type="int" column="participant_data_id" >
<generator class="increment"/>
</id>
<one-to-one name="pickedData" class="com.mep.model.DataValues" cascade="all" constrained="true"/>
<one-to-one name="averageData" class="com.mep.model.DataValues" cascade="all" constrained="true"/>
</class>
</hibernate-mapping>
数据值:
<hibernate-mapping>
<class name="com.mep.model.DataValues" table="data_values">
<id name="id" type="int" column="data_values_id">
<generator class="increment" />
</id>
<property name="n1" type="float" column="n1" />
<property name="s1" type="float" column="s1" />
<property name="x1" type="float" column="x1" />
<property name="a" type="float" column="a" />
<property name="b" type="float" column="b" />
<one-to-one name="participantData" class="com.mep.model.ParticipantData"
cascade="all"></one-to-one>
</class>
</hibernate-mapping>
我将不胜感激任何帮助:)