How to change datastore(main to additional) of an addon entity

Hi team,

Need your kind advise.

Say, I have ProjectA, ProjectB all plugged with MyAddon. And I defined an entity name MyAddonEntity.

For ProjectA, I want MyAddonEntity linked to the main datastore of ProjectA.
But for ProjectB, MyAddonEntity need to be linked to an additional datastore defined by ProjectB.

Is there any solution? Change dynamically by code, or statically by config file are all ok with my case.

thank you.

Hi,
This is possible.

  1. In the MyAddon, MyAddonEntity is mentioned in the persistence.xml.
    You should open app component descriptor app-component.xml and remove exporting the cuba.persistenceConfig property:
<!--
<property name="cuba.persistenceConfig" value="+com/company/myuni/persistence.xml"/>
-->
  1. In the ProjectA - manually add mentioned above persistence.xml to the list of persistence files of the main datastore, in web-app.properties and app.properties:
cuba.persistenceConfig = +com/company/myaddon/persistence.xml com/company/projecta/persistence.xml

  1. In the ProjectB - add the file to the list of persistence files for the additional datastore:
cuba.persistenceConfig_additional=+com/company/myaddon/persistence.xml com/sample/projectb/additional-persistence.xml

1 Like

thanks, Alex, this is what I need

Hi Alex,

Your above solution works, but recently i just found one small issue.

For ProjectB, where I add Addon’s persistence.xml to additional store, still generate DB init script for Main Store and addon’s table will be created.

But in runtime, the data will not be stored in mainStore, but into the additional DB correctly, leaving an annoying empty useless table in mainstore.

Is this expected?

thanks

Hi,
It’s probably one of these bugs:
https://youtrack.cuba-platform.com/issue/STUDIO-8341
https://youtrack.cuba-platform.com/issue/STUDIO-8502

They are already fixed and fixes will be available in next Studio release.

noted, thank you