public class Risk {
private long riskID;
private Vehicle vehicle;
}
public class Vehicle {
private long vehicleID;
private long riskID;
private String regNumber;
private String abiCode;
private String make;
private String model;
}
如果我将风险写入数据库,然后在网页上更改车辆并尝试第二次保存风险到数据库。我希望在风险表中有两个风险,在车辆表中有两个车辆。
目前我正在使用Hibernate Session Save(Object o)。这总是在数据库中创建一个新的风险,但从未创建一个新的车辆。它只是更新原始的车辆。
以下是我的映射文件:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class lazy="false" name="uk.co.test.Risk" schema="quote_engine" table="GV_RISK" >
<id column="riskID" name="riskID" type="long">
<generator class="identity"/>
</id>
<many-to-one name="vehicle" class="uk.co.test.Vehicle" column="vehicleID" not-null="true" cascade="all" unique="true" />
</class>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="uk.co.test.Vehicle" schema="quote_engine" table="GV_VEHICLE">
<id name="vehicleID" type="long" column="vehicleID">
<generator class="identity" />
</id>
<property name="regNumber" type="string" column="regNumber" />
<property name="abiCode" type="string" column="abiCode" />
<property name="make" type="string" column="make" />
<property name="model" type="string" column="model" />
</class>
Vehicle
的映射文件在哪里? - Perception