Re: How can I handle 1:1 relationships?

Iris Soto <[email protected]>
Newsgroups gmane.comp.jakarta.ojb.user
Message-ID <[email protected]>
Armin Waibel escribió:
> Hi,
>
> Iris Soto wrote:
>> Hello all,
>> I've problems  to handle 1:1 relationships, I want this association 
>> is navigable on both sides, from person to passport and vice versa.
>> I'm working with OJB and Postgresql, how can i declare in the ojb 
>> descriptor, in the schema this type of relationships, i try this way, 
>> but i get the following error:
>> proxy.IndirectionHandler - Can not materialize object for Identity 
>> org.apache.ojb.Person{25} - using PBKey org.apache.ojb.broker.PBKey: 
>> jcdAlias=default, user=postgres, password=*****
>
> Which version of OJB do you use?
> Did you enable CGLib proxy support in OJB.properties file?
> Did your test pass without using proxied references?
>
> In your mapping you don't use separate FK for the 1:1 references. This 
> could cause unexpected behavior when using proxy references. Assume 
> you are nullify the Passport of a Person. Next time you materialize 
> the Person object OJB tries to resolve the reference to Passport by 
> lookup the FK defined in Person. You define the Person PK as FK for 
> Passport reference (the FK to Passport could never be nullified), thus 
> OJB assume that the reference to Passport still exists and create a 
> proxy reference (instead of setting null). If you now try to access 
> the Passport reference in Person you will get a NPE, because OJB can't 
> find the Passport object.
>
> regards,
> Armin
>
Hello Armin, thanks for ask me,
the version of OJB that i'm using is y.IndirectionHandler -1.0.4, in the 
OJB.properties file i  have enable CGLib proxy support. I has been try 
test pass without using proxied references, and there is nothing 
different, the error is the same. I want to make bidirectional reference 
even though the passport is null when make reference in person
to passport. OJB can work with this null reference?

Now I have:

****************************************************************
<class-descriptor class="org.apache.ojb.Person" table="PERSON">
       <field-descriptor name="personId" primarykey="true" 
nullable="false" autoincrement="true"... column="PERSON_ID" 
jdbc-type="INTEGER"/>
     <field-descriptor name="personName" nullable="false" 
default-fetch="true" column="PERSON_NAME" jdbc-type="VARCHAR"/>
       <reference-descriptor name="personIdRef" 
class-ref="org.apache.ojb.Passport" auto-update="true" auto-delete="true">
         <foreignkey field-ref="personId"/>
       </reference-descriptor>
</class-descriptor>
****************************************************************
<class-descriptor class="org.apache.ojb.Passport" table="PASSPORT">
     <field-descriptor name="personId" primarykey="true" 
nullable="false" column="PERSON_ID" jdbc-type="INTEGER"/>
     <field-descriptor name="passport_number" nullable="false" 
default-fetch="true" column="PASSPORT_NUMBER" jdbc-type="VARCHAR"/>
     <reference-descriptor name="personIdRef" 
class-ref="org.apache.ojb.Person" auto-update="false" auto-delete="false">
         <foreignkey field-ref="personId"/>
       </reference-descriptor>
   </class-descriptor>

--
Iris Soto
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.