cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tobias Wolff <wo...@evaluegroup.com>
Subject Deleting n:m relationships
Date Tue, 31 Jul 2012 21:00:03 GMT
Hi,

I am currently trying to do the following in Cayenne 3.0.2:

  * fetch an object A
  * delete some related objects which are related to A in an n:m relation
  * add new objects to A (same n:m relation)

I have undergone a couple of java.util.ConcurrentModificationException 
and org.apache.cayenne.validation.ValidationException exception without 
being able to fix them. Here is some code, but a general hint on how to 
achieve that (especially when to do commits) would be much appreciated.

  * Class Forecast
  * Class LineItem
  * Class ForecastCondendingLineItem (n:m relation between Forecast and
    LineItem)

I have an object F of class Forecast which I have pulled from the 
database. Now I try to delete the n:m relations like this:

for(ForecastContendingLineItem temp : 
F.getForecastContendingLineItemArray()) {
   F.removeFromForecastContendingLineItemArray(temp);
   context.deleteObject(temp);
}

This results in the ConcurrentModificationException. I also tried this:

context.deleteObjects(F.getForecastContendingLineItemArray());

There is no exception, but I do not see any DELETE statements in the log 
either (probably I shoudn't!?). Then later on I try to add new n:m 
relations like this:

             relation = 
config.context().newObject(ForecastContendingLineItem.class);
             relation.setToForecast(_forecastItem);
             relation.setToLineItem(contendingLineItem);
             relation.setUsedImpressions(0L);
             relation.setOsi(0L);

But this results in the following a ""Validation failure for 
ch.goldbach.lib.ForecastContendingLineItem.toForecast: "toForecast"  is 
required."" exception although my feeling is that I do set the 
ToForecast relation through "setToForecast", no?

Anyone can help me out?

Thanks,
   Tobias.


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message