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 Mariusz Wójcik <wo...@okno.pw.edu.pl> on 2004/08/31 10:59:53 UTC
Problem with inserts and updates by OTM (m:n relationship) - OJB
tries to delete my objects - WHY ?????
Hi
I'm using ojb rc-7.0, and I have problems with inserting some of my
objects to db (by OTM). Sometimes ( It's very strange, because I have
mapped a lot of m:n references, but my problems concern the only one
(why???? - I don't know....)).
During inserting or updating objects my database ( Oracle 9i ) throws
Exception ( java.sql.SQLException: ORA-02291:integrity constraint
(%s.%s) violated - parent key not found) .
I debugged my JDBC connection, and I saw that OJB sends to my db
DELETE commands... WHY ????
Why does OJB try to delete my objects during INSERT or UPDATE operations
??? I don't want to delete any objects.
I don't understand it... What is the cause of this strange behaviour???
Maybe I have made a mistake in repository.xml, during object mapping ???
I have set those parameters: ( auto-retrieve="true" otm-dependent="true"
auto-delete="false" auto-update="false").
I haven't got any ideas.... It's a huge problem for me...
Thanks for help
Best regards
mario
This is the code of my insert, update method:
***********************************
OTMKit kit = SimpleKit.getInstance();
OTMConnection conn = null;
Transaction tx = null;
try {
conn =
kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
tx = kit.getTransaction(conn);
tx.begin();
conn.makePersistent(jo);
tx.commit();
} catch (LockingException e) {
********************************
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Problem with inserts and updates by OTM (m:n relationship) -
OJB tries to delete my objects - WHY ?????
Posted by "Ludovic Maitre (POP - Factory Part)" <lm...@factory-part.com>.
Hello,
As far as i know for managing the relationships OJB do this (in 1.0, but
it seems to be a generic design for updating relation in a database,
i've done the same when i was writing my own persistence layer)) :
- it delete the existing records of the relationship for the object you
want to update/store
- it recreate a record for each item in the relationship, based on what
is stored in memory for the object (i.e jo in your example).
In your case i suspect that the object that you insert hasn't been
entirely write to db [if it's a creation for example], so it has a
primary key with a negative value ("-37" for example) provided by OJB
which don't fit with the rules for the primary key that you have wrote
in your schema for the database (example: the pk must be > 0).
But perhaps it's something totally different... The best way to
understand this is to read the source code as i have done. It's well
written and understandable, in my point of view.
@+
Ludo
Mariusz Wójcik wrote:
> Hi I'm using ojb rc-7.0, and I have problems with inserting some of my
> objects to db (by OTM). Sometimes ( It's very strange, because I
> have mapped a lot of m:n references, but my problems concern the only
> one (why???? - I don't know....)).
> During inserting or updating objects my database ( Oracle 9i ) throws
> Exception ( java.sql.SQLException: ORA-02291:integrity constraint
> (%s.%s) violated - parent key not found) .
>
> I debugged my JDBC connection, and I saw that OJB sends to my db
> DELETE commands... WHY ????
>
> Why does OJB try to delete my objects during INSERT or UPDATE
> operations ??? I don't want to delete any objects.
> I don't understand it... What is the cause of this strange
> behaviour??? Maybe I have made a mistake in repository.xml, during
> object mapping ??? I have set those parameters: ( auto-retrieve="true"
> otm-dependent="true" auto-delete="false" auto-update="false").
> I haven't got any ideas.... It's a huge problem for me...
>
> Thanks for help
>
> Best regards
> mario
>
> This is the code of my insert, update method:
> ***********************************
> OTMKit kit = SimpleKit.getInstance();
> OTMConnection conn = null;
> Transaction tx = null;
> try {
> conn =
>
> kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
> tx = kit.getTransaction(conn);
> tx.begin();
> conn.makePersistent(jo);
> tx.commit(); } catch
> (LockingException e) {
> ********************************
>
> ---------------------------------------------------------------------
> 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