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 Armin Waibel <ar...@apache.org> on 2005/04/11 11:19:54 UTC

Re: [OJB-ODMG] foreign key constraint

Hi Jean-Yves,

 > I always have a violation of foreign key constraint, because  OJB seem's
 > to try to persists instance of this class before the instance of
 > Location linked with it.
 >
 > Is that normal ? Do I have to persists the Location object first, or is
 > OJB supposed to be able to deal with that ?


Which version of OJB do you use?
When using 1:1 references OJB "normally" persists the referenced object 
before the main object, so

DocumentBaseContent dbc = new ...
Location loc = new...
dbc.setLocation(loc)
tx.begin()
database.makePersistent(dbc)
tx.commit()

should work (no need to specify the Location object, it will be detected 
by OJB).
Except when using circular- or bidirectional 1:1 references, in this 
case you have to take care of order (hope we can fix this till next 
release). A workaround is shown in the bug report in jira
http://issues.apache.org/jira/browse/OJB-18

DocumentBaseContent dbc = new ...
Location loc = new...
dbc.setLocation(loc)
tx.begin()
database.makePersistent(loc)
database.makePersistent(dbc)
tx.commit()

or

DocumentBaseContent dbc = new ...
Location loc = new...
tx.begin()
database.makePersistent(dbc)
tx.flush()
dbc.setLocation(loc)
tx.commit()

regards,
Armin

jys wrote:
> Hello,
> 
> I have a problem (probably simple) trying to persist a Class looking 
> like this :
> 
> .....
> 
> * @ojb.class proxy="dynamic"
> *
> * @ojb.field name="locationId" jdbc-type="VARCHAR" nullable="false"
> *
> * @author jys
> */
> public class DocumentBaseContent implements IDocumentBaseContent {
> .....
> 
> 
>    /**
>     * location
>     *
>     * @ojb.reference foreignkey="locationId" auto-update="none" 
> auto-delete="none"
>     */
>    private Location locationsRoot = null;
> 
> .....
> 
> 
> }
> 
> I always have a violation of foreign key constraint, because  OJB seem's 
> to try to persists instance of this class before the instance of 
> Location linked with it.
> 
> Is that normal ? Do I have to persists the Location object first, or is 
> OJB supposed to be able to deal with that ?
> 
> Thanks for your help.
> 
> Jean-Yves
> 
> P.S:
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: [OJB-ODMG] foreign key constraint

Posted by Armin Waibel <ar...@apache.org>.
jys wrote:
> 
> I think this is maybe an OBJ bug because when i add 
> database-foreignkey="false" everything works fine. I'll post the classes 
> and repository so you can setup a test if you want.
>

if possible, please create an bug report in jira
http://issues.apache.org/jira/browse/OJB

and attach your files.

regards,
Armin


> Armin Waibel wrote:
> 
>> jyjeanyves@free.fr wrote:
>>
>>> Thanks for your answer Armin,
>>>
>>> I'am using OJB 1.0.3, but instead of
>>>
>>> database.makePersistent(dbc)
>>>
>>> i'am using
>>>
>>> tx.lock(dbc, WRITE)
>>>
>>> Don't know if it matters.
>>>
>>
>> This shouldn't matter, but it's recommended to use
>> database.makePersistent(dbc)
>> when insert new objects.
>>
>>
>>> The relation is a simple 1:1, but the Location object has itself 
>>> childs that are
>>> Location too, so maybe that's not so simple because OJB has to 
>>> persists the
>>> "tree" of Location first, anyway i'll try your solution tonight and 
>>> i'll post
>>> more detail.
>>>
>>
>> If it doesn't work please post your test case with details (classes, 
>> repository), so that I can setup an test for OJB test-suite.
>>
>> regards,
>> Armin
>>
>>
>>> Thank you.
>>>
>>> Jean-Yves
>>>
>>>
>>>
>>> Quoting Armin Waibel <ar...@apache.org>:
>>>
>>>
>>>> Hi Jean-Yves,
>>>>
>>>> > I always have a violation of foreign key constraint, because  OJB 
>>>> seem's
>>>> > to try to persists instance of this class before the instance of
>>>> > Location linked with it.
>>>> >
>>>> > Is that normal ? Do I have to persists the Location object first, 
>>>> or is
>>>> > OJB supposed to be able to deal with that ?
>>>>
>>>>
>>>> Which version of OJB do you use?
>>>> When using 1:1 references OJB "normally" persists the referenced object
>>>> before the main object, so
>>>>
>>>> DocumentBaseContent dbc = new ...
>>>> Location loc = new...
>>>> dbc.setLocation(loc)
>>>> tx.begin()
>>>> database.makePersistent(dbc)
>>>> tx.commit()
>>>>
>>>> should work (no need to specify the Location object, it will be 
>>>> detected
>>>> by OJB).
>>>> Except when using circular- or bidirectional 1:1 references, in this
>>>> case you have to take care of order (hope we can fix this till next
>>>> release). A workaround is shown in the bug report in jira
>>>> http://issues.apache.org/jira/browse/OJB-18
>>>>
>>>> DocumentBaseContent dbc = new ...
>>>> Location loc = new...
>>>> dbc.setLocation(loc)
>>>> tx.begin()
>>>> database.makePersistent(loc)
>>>> database.makePersistent(dbc)
>>>> tx.commit()
>>>>
>>>> or
>>>>
>>>> DocumentBaseContent dbc = new ...
>>>> Location loc = new...
>>>> tx.begin()
>>>> database.makePersistent(dbc)
>>>> tx.flush()
>>>> dbc.setLocation(loc)
>>>> tx.commit()
>>>>
>>>> regards,
>>>> Armin
>>>>
>>>> jys wrote:
>>>>
>>>>> Hello,
>>>>>
>>>>> I have a problem (probably simple) trying to persist a Class looking
>>>>> like this :
>>>>>
>>>>> .....
>>>>>
>>>>> * @ojb.class proxy="dynamic"
>>>>> *
>>>>> * @ojb.field name="locationId" jdbc-type="VARCHAR" nullable="false"
>>>>> *
>>>>> * @author jys
>>>>> */
>>>>> public class DocumentBaseContent implements IDocumentBaseContent {
>>>>> .....
>>>>>
>>>>>
>>>>>   /**
>>>>>    * location
>>>>>    *
>>>>>    * @ojb.reference foreignkey="locationId" auto-update="none"
>>>>> auto-delete="none"
>>>>>    */
>>>>>   private Location locationsRoot = null;
>>>>>
>>>>> .....
>>>>>
>>>>>
>>>>> }
>>>>>
>>>>> I always have a violation of foreign key constraint, because  OJB 
>>>>> seem's
>>>>> to try to persists instance of this class before the instance of
>>>>> Location linked with it.
>>>>>
>>>>> Is that normal ? Do I have to persists the Location object first, 
>>>>> or is
>>>>> OJB supposed to be able to deal with that ?
>>>>>
>>>>> Thanks for your help.
>>>>>
>>>>> Jean-Yves
>>>>>
>>>>> P.S:
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>
>>>>
>>>
>>>
>>>
>>> -- 
>>> Jean-Yves Sironneau
>>> jys@fr.st
>>> 06.16.18.71.63
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: [OJB-ODMG] foreign key constraint

Posted by jys <jy...@fr.st>.
I think this is maybe an OBJ bug because when i add 
database-foreignkey="false" everything works fine. I'll post the classes 
and repository so you can setup a test if you want.

Armin Waibel wrote:

> jyjeanyves@free.fr wrote:
>
>> Thanks for your answer Armin,
>>
>> I'am using OJB 1.0.3, but instead of
>>
>> database.makePersistent(dbc)
>>
>> i'am using
>>
>> tx.lock(dbc, WRITE)
>>
>> Don't know if it matters.
>>
>
> This shouldn't matter, but it's recommended to use
> database.makePersistent(dbc)
> when insert new objects.
>
>
>> The relation is a simple 1:1, but the Location object has itself 
>> childs that are
>> Location too, so maybe that's not so simple because OJB has to 
>> persists the
>> "tree" of Location first, anyway i'll try your solution tonight and 
>> i'll post
>> more detail.
>>
>
> If it doesn't work please post your test case with details (classes, 
> repository), so that I can setup an test for OJB test-suite.
>
> regards,
> Armin
>
>
>> Thank you.
>>
>> Jean-Yves
>>
>>
>>
>> Quoting Armin Waibel <ar...@apache.org>:
>>
>>
>>> Hi Jean-Yves,
>>>
>>> > I always have a violation of foreign key constraint, because  OJB 
>>> seem's
>>> > to try to persists instance of this class before the instance of
>>> > Location linked with it.
>>> >
>>> > Is that normal ? Do I have to persists the Location object first, 
>>> or is
>>> > OJB supposed to be able to deal with that ?
>>>
>>>
>>> Which version of OJB do you use?
>>> When using 1:1 references OJB "normally" persists the referenced object
>>> before the main object, so
>>>
>>> DocumentBaseContent dbc = new ...
>>> Location loc = new...
>>> dbc.setLocation(loc)
>>> tx.begin()
>>> database.makePersistent(dbc)
>>> tx.commit()
>>>
>>> should work (no need to specify the Location object, it will be 
>>> detected
>>> by OJB).
>>> Except when using circular- or bidirectional 1:1 references, in this
>>> case you have to take care of order (hope we can fix this till next
>>> release). A workaround is shown in the bug report in jira
>>> http://issues.apache.org/jira/browse/OJB-18
>>>
>>> DocumentBaseContent dbc = new ...
>>> Location loc = new...
>>> dbc.setLocation(loc)
>>> tx.begin()
>>> database.makePersistent(loc)
>>> database.makePersistent(dbc)
>>> tx.commit()
>>>
>>> or
>>>
>>> DocumentBaseContent dbc = new ...
>>> Location loc = new...
>>> tx.begin()
>>> database.makePersistent(dbc)
>>> tx.flush()
>>> dbc.setLocation(loc)
>>> tx.commit()
>>>
>>> regards,
>>> Armin
>>>
>>> jys wrote:
>>>
>>>> Hello,
>>>>
>>>> I have a problem (probably simple) trying to persist a Class looking
>>>> like this :
>>>>
>>>> .....
>>>>
>>>> * @ojb.class proxy="dynamic"
>>>> *
>>>> * @ojb.field name="locationId" jdbc-type="VARCHAR" nullable="false"
>>>> *
>>>> * @author jys
>>>> */
>>>> public class DocumentBaseContent implements IDocumentBaseContent {
>>>> .....
>>>>
>>>>
>>>>   /**
>>>>    * location
>>>>    *
>>>>    * @ojb.reference foreignkey="locationId" auto-update="none"
>>>> auto-delete="none"
>>>>    */
>>>>   private Location locationsRoot = null;
>>>>
>>>> .....
>>>>
>>>>
>>>> }
>>>>
>>>> I always have a violation of foreign key constraint, because  OJB 
>>>> seem's
>>>> to try to persists instance of this class before the instance of
>>>> Location linked with it.
>>>>
>>>> Is that normal ? Do I have to persists the Location object first, 
>>>> or is
>>>> OJB supposed to be able to deal with that ?
>>>>
>>>> Thanks for your help.
>>>>
>>>> Jean-Yves
>>>>
>>>> P.S:
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>
>>
>>
>> -- 
>> Jean-Yves Sironneau
>> jys@fr.st
>> 06.16.18.71.63
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: [OJB-ODMG] foreign key constraint

Posted by Armin Waibel <ar...@apache.org>.
jyjeanyves@free.fr wrote:
> Thanks for your answer Armin,
> 
> I'am using OJB 1.0.3, but instead of
> 
> database.makePersistent(dbc)
> 
> i'am using
> 
> tx.lock(dbc, WRITE)
> 
> Don't know if it matters.
>

This shouldn't matter, but it's recommended to use
database.makePersistent(dbc)
when insert new objects.


> The relation is a simple 1:1, but the Location object has itself childs that are
> Location too, so maybe that's not so simple because OJB has to persists the
> "tree" of Location first, anyway i'll try your solution tonight and i'll post
> more detail.
>

If it doesn't work please post your test case with details (classes, 
repository), so that I can setup an test for OJB test-suite.

regards,
Armin


> Thank you.
> 
> Jean-Yves
> 
> 
> 
> Quoting Armin Waibel <ar...@apache.org>:
> 
> 
>>Hi Jean-Yves,
>>
>> > I always have a violation of foreign key constraint, because  OJB seem's
>> > to try to persists instance of this class before the instance of
>> > Location linked with it.
>> >
>> > Is that normal ? Do I have to persists the Location object first, or is
>> > OJB supposed to be able to deal with that ?
>>
>>
>>Which version of OJB do you use?
>>When using 1:1 references OJB "normally" persists the referenced object
>>before the main object, so
>>
>>DocumentBaseContent dbc = new ...
>>Location loc = new...
>>dbc.setLocation(loc)
>>tx.begin()
>>database.makePersistent(dbc)
>>tx.commit()
>>
>>should work (no need to specify the Location object, it will be detected
>>by OJB).
>>Except when using circular- or bidirectional 1:1 references, in this
>>case you have to take care of order (hope we can fix this till next
>>release). A workaround is shown in the bug report in jira
>>http://issues.apache.org/jira/browse/OJB-18
>>
>>DocumentBaseContent dbc = new ...
>>Location loc = new...
>>dbc.setLocation(loc)
>>tx.begin()
>>database.makePersistent(loc)
>>database.makePersistent(dbc)
>>tx.commit()
>>
>>or
>>
>>DocumentBaseContent dbc = new ...
>>Location loc = new...
>>tx.begin()
>>database.makePersistent(dbc)
>>tx.flush()
>>dbc.setLocation(loc)
>>tx.commit()
>>
>>regards,
>>Armin
>>
>>jys wrote:
>>
>>>Hello,
>>>
>>>I have a problem (probably simple) trying to persist a Class looking
>>>like this :
>>>
>>>.....
>>>
>>>* @ojb.class proxy="dynamic"
>>>*
>>>* @ojb.field name="locationId" jdbc-type="VARCHAR" nullable="false"
>>>*
>>>* @author jys
>>>*/
>>>public class DocumentBaseContent implements IDocumentBaseContent {
>>>.....
>>>
>>>
>>>   /**
>>>    * location
>>>    *
>>>    * @ojb.reference foreignkey="locationId" auto-update="none"
>>>auto-delete="none"
>>>    */
>>>   private Location locationsRoot = null;
>>>
>>>.....
>>>
>>>
>>>}
>>>
>>>I always have a violation of foreign key constraint, because  OJB seem's
>>>to try to persists instance of this class before the instance of
>>>Location linked with it.
>>>
>>>Is that normal ? Do I have to persists the Location object first, or is
>>>OJB supposed to be able to deal with that ?
>>>
>>>Thanks for your help.
>>>
>>>Jean-Yves
>>>
>>>P.S:
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
> 
> 
> 
> --
> Jean-Yves Sironneau
> jys@fr.st
> 06.16.18.71.63
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: [OJB-ODMG] foreign key constraint

Posted by jy...@free.fr.
Thanks for your answer Armin,

I'am using OJB 1.0.3, but instead of

database.makePersistent(dbc)

i'am using

tx.lock(dbc, WRITE)

Don't know if it matters.

The relation is a simple 1:1, but the Location object has itself childs that are
Location too, so maybe that's not so simple because OJB has to persists the
"tree" of Location first, anyway i'll try your solution tonight and i'll post
more detail.

Thank you.

Jean-Yves



Quoting Armin Waibel <ar...@apache.org>:

> Hi Jean-Yves,
>
>  > I always have a violation of foreign key constraint, because  OJB seem's
>  > to try to persists instance of this class before the instance of
>  > Location linked with it.
>  >
>  > Is that normal ? Do I have to persists the Location object first, or is
>  > OJB supposed to be able to deal with that ?
>
>
> Which version of OJB do you use?
> When using 1:1 references OJB "normally" persists the referenced object
> before the main object, so
>
> DocumentBaseContent dbc = new ...
> Location loc = new...
> dbc.setLocation(loc)
> tx.begin()
> database.makePersistent(dbc)
> tx.commit()
>
> should work (no need to specify the Location object, it will be detected
> by OJB).
> Except when using circular- or bidirectional 1:1 references, in this
> case you have to take care of order (hope we can fix this till next
> release). A workaround is shown in the bug report in jira
> http://issues.apache.org/jira/browse/OJB-18
>
> DocumentBaseContent dbc = new ...
> Location loc = new...
> dbc.setLocation(loc)
> tx.begin()
> database.makePersistent(loc)
> database.makePersistent(dbc)
> tx.commit()
>
> or
>
> DocumentBaseContent dbc = new ...
> Location loc = new...
> tx.begin()
> database.makePersistent(dbc)
> tx.flush()
> dbc.setLocation(loc)
> tx.commit()
>
> regards,
> Armin
>
> jys wrote:
> > Hello,
> >
> > I have a problem (probably simple) trying to persist a Class looking
> > like this :
> >
> > .....
> >
> > * @ojb.class proxy="dynamic"
> > *
> > * @ojb.field name="locationId" jdbc-type="VARCHAR" nullable="false"
> > *
> > * @author jys
> > */
> > public class DocumentBaseContent implements IDocumentBaseContent {
> > .....
> >
> >
> >    /**
> >     * location
> >     *
> >     * @ojb.reference foreignkey="locationId" auto-update="none"
> > auto-delete="none"
> >     */
> >    private Location locationsRoot = null;
> >
> > .....
> >
> >
> > }
> >
> > I always have a violation of foreign key constraint, because  OJB seem's
> > to try to persists instance of this class before the instance of
> > Location linked with it.
> >
> > Is that normal ? Do I have to persists the Location object first, or is
> > OJB supposed to be able to deal with that ?
> >
> > Thanks for your help.
> >
> > Jean-Yves
> >
> > P.S:
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> > For additional commands, e-mail: ojb-user-help@db.apache.org
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>


--
Jean-Yves Sironneau
jys@fr.st
06.16.18.71.63

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org