Peter,

Just commit the changes you make in your master.
You don't need update.

db.begin();
db.load(master);
master.setItem(x);
master.setTestItem(y);
db.commit();
db.close();

The update is in changing your master object and commit this one.

Good luck.

Robin Hoogeboom


----- Origineel Bericht -----
Van: Peter Jeszenszky <[EMAIL PROTECTED]>
Datum: Vrijdag, November 22, 2002 9:45 pm
Onderwerp: [castor-dev] 1:N update problem

> Hello,
> 
> I have a master object with N dependent objects. In the database
> table of the dependent objects there is a UNIQUE constraint:
> 
>       CREATE TABLE dependent(
>               id      SERIAL  PRIMARY KEY,
>               master_id       INTEGER NOT NULL REFERENCES master ON 
DELETE 
> CASCADE,              value   VARCHAR(40),
>               UNIQUE(master_id, value)
>       );
> 
> Lets load a master object
> 
>       Database        db;
>       Master  m = (Master) db.load(Master.class, new Integer(1));
> 
> then remove all of its dependents with
> 
>       master.getDependents().removeAllElements();
> 
> then add a new dependent object with a value that just has been
> removed:
> 
>       master.addDependent(" A VALUE THAT JUST HAS BEEN REMOVED ");
> 
> The method invocation
> 
>       db.update(master);
> 
> results an exception
> 
>       java.sql.SQLException: ERROR:  Cannot insert a duplicate key
> 
> since Castor handles the dependent objects in the following order:
> 
>       1. First creates the dependent objects that are assigned to the 
> master.       (The UNIQUE constraint is violated!)
> 
>       2, Then removes the dependent objects that have been 
disassociated
>       from the master.
> 
> I thinks so these operations should be performed in the opposite 
> order.Is it a bug? Any idea to handle the situation?
> 
> Yours sincerely,
> 
> Peter
> 
> ----------------------------------------------------------- 
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>       unsubscribe castor-dev
> 
> 

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to