Different Container Datasources for read and write

Hi,

I’m fairly new to Vaadin so apologies if any of this sounds nonsence.

Conceptually, I have a ‘Project’ which has many ‘Tasks’, and each ‘Task’ can have many ‘Projects’. I have modelled this through JPA using a Many-to-Many relationship via a join table.

I am using a TwinColSelect component to display the full list of tasks available when creating a project.

The tasks are added to the TwinColSelect via a BeanItemContainer set as the container datasource.

The entity is mananged via Fieldgroup using BeanItem as the datasource, and the TwinColSelect is bound to the ‘Set tasks’ in the JPA Project entity.

When the FieldGroup is commit(), the Project entity contains a Set of the selected tasks and this is stored in the database. So far all is well.

Now… each task can have a ‘Rate’ stored against it. I have added the Rate column to the Many-To-Many join table. This means this entity should now be modelled, and is as Project → ProjectTaskAssociation ← Task. The JPA components have been updated and work fine.

What I want to do is have the datasource of the TwinColSelect still be BeanItemContainer, but I can’t bind it to the BeanItem datasource of the Fieldgroup as it now has a One-To-Many ProjectTaskAssociation link and not Task

I can’t set the TwinColSelect datasource as BeanItemContainer as it will be always be empty when creating a Project.

Ideally I need to convert my selected Lists to Lists when calling getValue(). I’ve tried with a convertor but it didn’t appear to do anything and I suspect I’m barking up the wrong tree completely here.

I’m pretty stuck for ideas so any advice from you more experienced Vaadin users would be very much appreciated,

Thanks,
Simon