[bug] unable to remove an item from a composition list

6 posts / 0 new
Last post
atao
Offline
Joined: 10/15/2008
[bug] unable to remove an item from a composition list

Hello,

I have a chain of compositions:

Branch.workers (set) ---> Worker.contracts(list) ---> Contract.paylsips (list)  ...

Each item of a composition knows its parent: worker.branch, contract.worker, payslip.contract. All of these attributes are specified as mandatory.

Everything runs fine when I try to remove:

- a worker from a branch;

- a contract from a worker.

But I get an integrity.property.mandatory message when I try to remove a payslip from a contract.

The issue is created by AbstractComponentInvocationHandler.invoke(proxy, method, args).

When accessorInfo.isModifier() is true, jspresso checks if modifierMonitors contains already method.getName():

- if it's the case, then it quits immediatly the method and everything is fine;

- otherwise, it adds the method name to modifierMonitors and ... continues. Then when propertyDescriptor.preprocessSetter(proxy, actualNewProperty) is called, as payslip.contract is mandatory, the message aboves is thrown.

IMO, with a composition, there is no reason to reset the value of the reverse property.

I fear I miss something obvious, but ATM in AbstractComponentInvocationHandler.removeFromProperty.removeFromProperty, I use this patch:

      if (collectionProperty.contains(value)) {
        IRelationshipEndPropertyDescriptor reversePropertyDescriptor = propertyDescriptor
            .getReverseRelationEnd();
        if (reversePropertyDescriptor != null) {
          if (!propertyDescriptor.isComposition() &&
            (reversePropertyDescriptor instanceof IReferencePropertyDescriptor<?>)) {

      [...]

Pierre

 

 

vvandens
Offline
Joined: 05/29/2008
[bug] unable to remove an item from a composition list

Hi Pierre,

Are you trying to remove and delete the payslip from the composition using the standard Jspresso action or only calling the Contract.removeFromPayslips method ?

A few remarks :

  • Jspresso will always ensure that mandatory properties are never made null, even temporarilly in memory. So in that case, a Payslip cannot be removed from its owning Contract. However, it can be tranferred to another contract either using contract2.addToPayslips or payslip.setContract(contract2).
  • I don't think that composition semantics should change anything about that, but maybe am I wrong ? Using a composition does not mean that an element cannot be transferred to another parent (?)
  • Of course, there is an exception when you actually want to remove and delete a payslip. Jspresso standard action will clean all the payslip's relationships (including contract) and remove it from associations before actually deleting it. This is achieved by temporarilly disabling property processors by calling setPropertyProcessorsEnabled(false). Of course, this has to be used with extreme caution. You can see the deletion management in this source code. The principle is the following : a dry run is performed with all processors enabled (processors are actually manually triggered). Once validated, the actual run is performed with processors disabled.

 

HTH,

Vincent

atao
Offline
Joined: 10/15/2008
[bug] unable to remove an item from a composition list

Vincent,

Are you trying to remove and delete the payslip from the composition using the standard Jspresso action or only calling the Contract.removeFromPayslips method ?

I'm using removeAnyCollectionFromMasterFrontAction, and yes it's to delete the payslip, not to transfert it to an other contract.

Jspresso will always ensure that mandatory properties are never made null

I used the mandatory attribut of payslip.contract to be sure there would be no orphan payslip. So here the expected semantic is: to remove a payslip is to delete it.

I don't think that composition semantics should change anything about that, but maybe am I wrong ? Using a composition does not mean that an element cannot be transferred to another parent (?)

True. Even if in the present case, to transfert a payslip from a contract to an other one would be meaningless.

Of course, there is an exception when you actually want to remove and delete a payslip

Oups. I missed something here. So removeAnyCollectionFromMasterFrontAction doesn't mean that after removing an element, it is deleted! Why not. But here, as I said just above, removing a payslip should be followed by a deletion.

A strange thing is, with branch.workers and worker.contracts, I use also removeAnyCollectionFromMasterFrontAction, with the same expected semantic, and everything seams to run fine... The issue occurs only with contract.payslips! I'm unable to figure out what is the difference.

So my question is now: how to configure  removeAnyCollectionFromMasterFrontAction to get a deletion. Or what bean to use in place of removeAnyCollectionFromMasterFrontAction. 

Regards

Pierre

 

 

vvandens
Offline
Joined: 05/29/2008
[bug] unable to remove an item from a composition list

Pierre,

you should use removeEntityCollectionFromMasterFrontAction that registers the removed entities for deletion and detaches/deletes their composed children. this action chains to the backend Hibernate aware removeCollectionFromMasterBackAction that performs the 2-steps deletion process I described in my previous post. This is the action that is part of the standard master/detail action map.

You can have a look to this documentation table. Although not very detailed, it can give you a good starting point for finding pre-defined actions.

HTH,

Vincent

atao
Offline
Joined: 10/15/2008
[bug] unable to remove an item from a composition list

Vincent,

I'm quite confused: it was so obvious Innocent

In fact the ActionMap used with worker and contract tables use already removeEntityCollectionFromMasterFrontAction as they are built from standard master/detail action map.

Only the ActionMap with payslips that I built from scratch used removeAnyCollectionFromMasterFrontAction. And indeed, as soon I changed it to removeEntityCollectionFromMasterFrontAction, it have been running as expected.

Thanks for your patience with my silly questions!

By the way, the  documentation table is very useful.

Regards

Pierre           

vvandens
Offline
Joined: 05/29/2008
[bug] unable to remove an item from a composition list

Pierre,

Don't worry about that. It happens to me all the time...