You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by jo...@on-ergy.de on 2005/07/27 09:39:31 UTC
Customizing 1:1 querys like customized collection queries | second trail
Hello OJB-Users,
I haven't get any feedback on this email yet, so I try it once more.
The problem is that the Informations from the Foreign key are Primary-Key
+ hardcoded String.
How can I add the hardcoded String to my 1:1 reference?
For 1:n, it's no Problem, because I can add the String to the Query in an
QueryCustomizer
----------------------------------------------------------------------------------------------------------------------
I have even started using OJB and so far all works fine :o) (1:1, 1:n...)
I would be pleased when you can help me with my first Problem.
I'm looking for an solution like 'Customizing collection queries'
descriped in the Guide 'advanced O/R technique' for 1:1 references.
A short example:
I have multible tables (named parts, driver...) and for each entry of a
table i can reference to ONE entry of a table named memo across the
primary-key as foreign key in the memo-table.
To have a unique key, I musst save a second value in the memo-table to
know from which table the foreign-key comes. This value is a String and is
hardcoded in the software.
For table parts i save = "part" in the table Memo field parentTable
For table driver i save = "driv" in the table Memo field parentTable
Now, when I'm loading the memo to an item of the parts-table, I want' only
load the memo where in table Memo parentTable="part"
With a 1:n, thats no Problem, because I can work with the query-customizer
like this
################################
<inverse-foreignkey field-ref="parentObjId"/>
<query-customizer
class="de.on_ergy.lakon.data.QueryCustomizerLakonImpl">
<attribute
attribute-name="parentTable"
attribute-value="TEILSTAM"
/>
</query-customizer>
################################
There I can add the value "TEILSTAM" to the Query with the written
QueryCustomizerLakonImpl
But how can I realize this with 1:1 ??
Thank you very very much for your help.
Best Wishes
Josef Wagner
/Germany
Re: Customizing 1:1 querys like customized collection queries | second
trail
Posted by Armin Waibel <ar...@apache.org>.
Hi Josef,
think this is not possible, because OJB handle 1:1 references different
from 1:n. 1:1 references are identity based (the main object knows the
PK values of the referenced object), so there is no need to use a
QueryCustomizer.
The 1:1 reference point from named parts, driver... to Memo - correct?
In your Memo table an entry/row is only unique when the PK is composed
of the PK of the main table (driver, ...) and a String field ("driv",
...)? If this is true, you have to declare both fields as PK in the
class-descriptor of the Memo class and the 1:1 reference in e.g. Driver
class look like this
<reference-descriptor
name="memo"
class-ref="Memo"
proxy="false"
auto-retrieve="true"
auto-update="true"
auto-delete="false">
<foreignkey field-ref="fkMemoId"/>
<foreignkey field-ref="fkMemoString"/>
</reference-descriptor>
Both FK fields are needed in Driver,...
If I it get it wrong, could you describe more detailed with
class-descriptor examples?
regards,
Armin
josef.wagner@on-ergy.de wrote:
> Hello OJB-Users,
> I haven't get any feedback on this email yet, so I try it once more.
> The problem is that the Informations from the Foreign key are Primary-Key
> + hardcoded String.
> How can I add the hardcoded String to my 1:1 reference?
> For 1:n, it's no Problem, because I can add the String to the Query in an
> QueryCustomizer
>
> ----------------------------------------------------------------------------------------------------------------------
>
> I have even started using OJB and so far all works fine :o) (1:1, 1:n...)
> I would be pleased when you can help me with my first Problem.
>
> I'm looking for an solution like 'Customizing collection queries'
> descriped in the Guide 'advanced O/R technique' for 1:1 references.
>
> A short example:
>
> I have multible tables (named parts, driver...) and for each entry of a
> table i can reference to ONE entry of a table named memo across the
> primary-key as foreign key in the memo-table.
> To have a unique key, I musst save a second value in the memo-table to
> know from which table the foreign-key comes. This value is a String and is
> hardcoded in the software.
> For table parts i save = "part" in the table Memo field parentTable
> For table driver i save = "driv" in the table Memo field parentTable
>
> Now, when I'm loading the memo to an item of the parts-table, I want' only
> load the memo where in table Memo parentTable="part"
>
> With a 1:n, thats no Problem, because I can work with the query-customizer
> like this
> ################################
> <inverse-foreignkey field-ref="parentObjId"/>
> <query-customizer
> class="de.on_ergy.lakon.data.QueryCustomizerLakonImpl">
> <attribute
> attribute-name="parentTable"
> attribute-value="TEILSTAM"
> />
> </query-customizer>
> ################################
>
> There I can add the value "TEILSTAM" to the Query with the written
> QueryCustomizerLakonImpl
>
> But how can I realize this with 1:1 ??
>
> Thank you very very much for your help.
>
> Best Wishes
>
> Josef Wagner
> /Germany
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org