[EMAIL PROTECTED] 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 <[EMAIL PROTECTED]>:


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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]




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





-- Jean-Yves Sironneau [EMAIL PROTECTED] 06.16.18.71.63

---------------------------------------------------------------------
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]



Reply via email to