This will help to see the DDL for each table. You use a many-to-one mapping for a one-to-one association using a unique foreign key association. If they share the same primary key, you can use one to one.
You can try to make a one-on-one bi-directional display in your vehicle mapping, but this is not necessary. This is how it would look.
<one-to-one name="risk" class="uk.co.test.Risk" property-ref="riskID"/>
However, what you are trying to do is largely contested. I could modify the class definitions a bit and double check your DDL.
For example (keeping the hbm mapping exactly the same as you defined above):
The structure of the table is as follows:
create table GV_VEHICLE ( vehicleID int(11) not null auto_increment, regNumber varchar(50) not null, abiCode varchar(50) not null, make varchar(50) not null, model varchar(50) not null, primary key(vehicleID))); create table GV_RISK ( riskID int(11) not null auto_increment, vehicleID int(11), primary key(riskID), foreign key(vehicleID) references GV_VEHICLE(vehicleID));
Create definitions from one to one class, each with confirmation to each other
public class Vehicle { private long vehicleID; private String regNumber; private String abiCode; private String make; private String model; private Risk risk; } public class Risk { private long riskID; private Vehicle vehicle; }
source share