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]



Reply via email to