cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tobias Wolff <wo...@evaluegroup.com>
Subject Re: Deleting n:m relationships
Date Wed, 01 Aug 2012 11:08:36 GMT
Hi again,

so, I now tried this:

         // Delete any condending ads
         for(ForecastContendingLineItem temp : 
_forecastItem.getForecastContendingLineItemArray()) {
_forecastItem.removeFromForecastContendingLineItemArray(temp);
         }

         // Now deal with the contending ads
         LineItem contendingLineItem = null;
         ForecastContendingLineItem relation = null;
         for(Integer tempId : result.getContendingAdIds()) {
           contendingLineItem = 
LineItemDfpInfo.getLineItemByDfpId(config.context(), tempId);
           if(contendingLineItem != null) {
             relation = new ForecastContendingLineItem();
             relation.setToForecast(_forecastItem);
             relation.setToLineItem(contendingLineItem);
             relation.setUsedImpressions(0L);
             relation.setOsi(0L);

_forecastItem.addToForecastContendingLineItemArray(relation);
           }
         }

So first, I am trying to remove the existing items from the list (first 
3 lines). Then I am adding the new once. I now get this:

org.apache.cayenne.validation.ValidationException: [v.3.0.2 Jun 11 2011 
09:31:18] Validation failures: Validation failure for 
ch.goldbach.lib.ForecastContendingLineItem.toForecast: "toForecast"  is 
required.
Validation failure for 
ch.goldbach.lib.ForecastContendingLineItem.toForecast: "toForecast"  is 
required.
     at 
org.apache.cayenne.access.ObjectStoreGraphDiff.validateAndCheckNoop(ObjectStoreGraphDiff.java:111)
     at 
org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1110)
     at 
org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:1060)

The "setToForecast" method says this:

     public void setToForecast(Forecast toForecast) {
         setToOneTarget("toForecast", toForecast, true);
     }

So, I am bit lost, why the line

     relation.setToForecast(_forecastItem);

does not seem to work. Any ideas?
Gruß/Regards,
Tobias.

*Adternity GmbH*

Kennedydamm 1
40476 Düsseldorf

Tonhallenstraße 16
47051 Duisburg

Tel.: +49 203 298685 37
eMail: wolff@adternity.net
Web: http://www.adternity.net

Geschäftsführer: Thomas Servatius, Tobias Wolff, Jörn Mika, Henrik Basten
Amtsgericht: Düsseldorf, HRB 60031
Steuer-Nr.: DE238773677
On 7/31/12 11:00 PM, Tobias Wolff wrote:
> 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