Ok I figured out the missing link. The missing link is that when you have a fk reference in one table to another the other table needs to have a collection with an inverse fk to the first since in the example I gave originally I had a many to one relationship between brokers and homes, many homes can have one broker in this case.

I got reverse-db to work on windows to SQL Server and I created the tables there with the foreign keys et al, then reversed the sucker to see what the result was.


On Thursday, Feb 13, 2003, at 13:58 US/Eastern, Matthew Baird wrote:

now I'm confused.

let's recap:
- objects are related based on foreign keys, right?
- you can load objects in ojb based on any value, either in PB or in odmg, so a select myclass where myclass.somerelatedobject.someattribute=? will work. OJB will generate the appropriate joins for you. queries can be run without inflating a proxy, since it is, at the end of the day, just a sql query.

"For example, if A refers to a B, then in order to make the query "Give me
all the As where B's name is X, do I have to really have all those B's
instantiated within the A's? I dont want to have to retrieve all those B's
from the database unless I actually want the B's."

psuedo-oql
select A.B where A.B.name='X' will return all the B's and if the reference to A is unidirectional from A, or marked lazy, then all the A's will only be materialized when you access them.



-----Original Message-----
From: David Mitchell [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 13, 2003 10:43 AM
To: 'OJB Users List'
Subject: RE: foreign keys... last time I swear :)



Ok, I guess I pretty much understand it. You use the reference name to do a
lookup on the referenced object. So if I want to join two tables on
something other than a primary key, I need to use a hand-written sql query.
Im okay with that.

I believe I will also have to use hand-written sql for my other joins,
because I cannot use either lazy-materialization for those foreign objects,
nor prefetch that object. I only want to be able to query by those fields
without ever actually obtaining the foreign object.

For example, if A refers to a B, then in order to make the query "Give me
all the As where B's name is X, do I have to really have all those B's
instantiated within the A's? I dont want to have to retrieve all those B's
from the database unless I actually want the B's.

In other words, I cant say "select A.* from A, B where a.b.name='XXX'",
unless I have already retrieved the B from the database, to know what it's
name is.

To answer myself, unless someone corrects my misunderstanding, I have to
still write my own SQL query. This is again just fine with me, as long as I
know it's the only way to do it.

-dave


-----Original Message-----
From: Matthew Baird [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 13, 2003 12:26 PM
To: OJB Users List
Subject: RE: foreign keys... again


the docs may not be clear, but the examples are pretty clear.
...


+---------------------------------------------------------+
This message may contain confidential and/or privileged information. If you
are not the addressee or authorized to receive this for the addressee, you
must not use, copy, disclose or take any action based on this message or any
information herein. If you have received this message in error, please
advise the sender immediately by reply e-mail and delete this message.
Thank you for your cooperation.
+---------------------------------------------------------+

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

R

--
Robert S. Sfeir
Senior Java Engineer
National Institutes of Health
Center for Information Technology
Department of Enterprise Custom Applications
[EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to