-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Foreign Key Mapping Design question
PostPosted: Wed Feb 09, 2005 5:16 am 
Beginner
Beginner

Joined: Thu Oct 14, 2004 5:07 am
Posts: 37
Location: Cambridge, UK
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


Top
 Profile  
 
 Post subject: Foreign key mapping
PostPosted: Wed Feb 09, 2005 7:50 am 
Beginner
Beginner

Joined: Thu Oct 14, 2004 5:07 am
Posts: 37
Location: Cambridge, UK
Right I got it working by keeping the association...

and instead of having to do a separate lookup for the 2 foreign key entities, I managed to just create 2 new instances (and set the identity on them)...

This worked fine, without having to reload the entities...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.