MultiSelectTable and bi-directional JPA relations

Hi,

Viritin’s MultiSelectTable can be used to edit n:m JPA relations.
However, MultiSelectTable seems to update the relationship via standard set/get bean operations.

My JPA code supposed bi-directional relationships.
Entities are added and removed by addRelName(Object) and removeRelName(Object) and
not by bean setters and getters.
The add and remove operations ensure that a relationship is updated bi-drectionally and not
single sided, so I have to use them.

Is it possible somehow to instruct MultiSelectTable to use my add/remove operations and not the
bean set/get methods?

Thanks,

JG

Hi, so you are updating bi-directional references in entities?

Maybe it would be enought to expose protected methods that modify the actual collection (addRelation/removeRelation) in the
setValue method
. You’d need to extend the MultiSelectTable and override those. For the extended class you also need to pass the object instace somehow as the (Method)Property effectively hides the (Bean)Item, but at least is should be possible then.

If you have an example of you entity that you could share, could you open an issue for this enhancment in github project page and post the example entity to the ticket?

cheers,
matti

Hi Matty,

Thanks for answer.
I followed more or less the road you suggest and it works now.
However, I want to remove a few workarounds I applied.

My solution is as follows:

I have a new version of the setValue method as follows:

protected void setValue(Object newValue, boolean repaintIsNotNeeded) throws ReadOnlyException {

if (clientSideChange) {

            ...
            //collection.removeAll(orphaned);  
            removeAll(orphaned);
            
           ...

            //collection.addAll(newValues);
            addAll(newValues);

            ...
        }
    }

The removeAll and andAll add and remove the objects from my JPA sets via the addRelName and removeRelName methods of my JPA object via java reflection.

There are two problems:

  1. I need to obtain a reference to JPA object edited by the form. Now, this references is obtained by calling
    AbstractForm form = (AbstractForm) getParent().getParent().getParent()
    to obtain the form (and then the object with getEntity). Is there a more elegant way to do this?
  2. I also need the RelName. I create the MultiSelectTable with
    @PropertyId(“relName”)
    MultiSelectTable relName = new MultiSelectTable …

I want to obtain the PropertyId (relName) in the MultiSelectTable implementation but so far, I did not succeed.
As a workaround, I have added the propertyId as a field in the MultiSelectTable, but it would better to obtain the annotation.

Additionally, the setValue method is part of the inner class table in MultiSelectTable. How can I override this?

Thanks

Hi,

If you have some suggestion of improvements, could you fill them
to the project page
. Also a reduced use case would be awesome to figure out the best way to make improvements.

cheers,
matti

Hi Matti,

After some delay, I posted some issues on the github page.

Best,

JG

Excellent, I’ll try to go through my github notifications next week. I have been too busy lately.

cheers,
matti

Hi Matty,

Found your update on github.
It works well for me.
Thanks.

JG