Hello
I'd like to know what is the best way to implement a 0-1 relation using OJB.
For example, let's say I have a table OWNER and a table CAT. Let's say an owner may have a cat (and only one), or not, and a cat always has an owner, so the table CAT contains a foreign key to the OWNER. When I want to display an owner, how to get his cat when he has one ?
What I did is to declare in repository for table OWNER a collection of cats with the inverse foreign key contained in CAT.
<collection-descriptor name="cats" element-class-ref="package.Cat" proxy="true">
<inverse-foreignkey field-ref="ownerId"/>
</collection-descriptor>
Class Owner looks like this
public class Owner
{
....List cats;
....
public List getCats()
{
return cats;
} public InterfaceCat getCat()
{
return this.getCats().get(0);
} public boolean hasCat()
{
return (this.getCats.size() > 0)?true:false;
}}
And in java code to get the cat, I do :
....
if (owner.hasCat())
cat = owner.getCat();
else
cat = null;
...This works great, but I don't know if a better (without passing by a collection) way exists (I may have missed something in the tutorials). Thanks in advance for any answer.
Thomas
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
