Hi
I have a wizard style interface in my web app that goes through 4 pages to add an 'Offence' Entity.
I am also trying to keep the user state request scope.
On page 1, the user selects entity 'Employee', so I then keep the employee id as a hidden field for the remaining 3 pages. On page 2, the user selects the FleetVehicle entity, so I then keep FleetVehicle ID on the remaining pages.
When I come to do the save, I have the two foreign key id's I need to persist my Offence entity so fine.
But I really want to setup the associations between Offence, Fleet Vehicle and Employee properly (ie. the commented out section in the hbm mapping file). If I do this, then I do not *think* I need to hold the id's, either in my POJO, or in the mapping document. (because I can call Offence.setEmployee (employeeDAO.loadEmployee(123)); and
Offence.setFleetVehicle (fleetDAO.loadFleetVehicle(234));
However, if I do this, I then need to execute a loadFleetVehicle and loadEmployee to make the association before I do the save.
What is the best approach here? It feels right to have the associations setup.... but I really dont want to have execute 2 SQL loads just to add the Employee and FleetVehicle entities to the Offence (ie. to maintain the integrity of the associations....)
I am guessing other people have come across this situation, or am I missing something here?
Hibernate version:2.1.7
Mapping documents:
Offence.hbm.xml:
<property name="fleetUuid" type="java.lang.String" column="FLEET_UUID" length="20" />
<property name="employeeUuid" type="java.lang.String" column="EMPLOYEE_UUID" length="20" />
<!-- TODO Decide whether to load the FleetVehicle instance into this or just go with holding the id <many-to-one name="fleetVehicle" class="com.ocado.tracker.fleet.pojo.FleetVehicle" column="fleet_uuid" not-null="false" />
<many-to-one name="employee" class="com.ocado.tracker.employees.pojo.Employee" column="employee_uuid" not-null="false" /> -->
Name and version of the database you are using:Oracle 9i
|