jmix-framework / jmix

Jmix framework
https://www.jmix.io
Apache License 2.0
487 stars 112 forks source link

Support multiple datasource inside dynamic attribute add-on #2354

Open glebfox opened 8 months ago

glebfox commented 8 months ago

Case:

  1. Create a dynamic attribute with entity type and entity class from a secondary data store
  2. Add dynamic attribute to screens
  3. Try to create an entity with dynamic attribute and fill its value
  4. Save

AR:

Local Exception Stack: 
Exception [EclipseLink-0] (Eclipse Persistence Services - 2.7.9.6-jmix): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Problem compiling [select e from Customer e where e.id in :ids]. 
[14, 22] The abstract schema type 'Customer' is unknown.
[31, 35] The state field path 'e.id' cannot be resolved to a valid type.
    at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildException(HermesParser.java:157)
    at org.eclipse.persistence.internal.jpa.jpql.HermesParser.validate(HermesParser.java:349)
    at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:280)
    at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildQuery(HermesParser.java:165)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:144)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:118)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:104)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:88)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1753)
    at io.jmix.eclipselink.impl.JmixEclipseLinkQuery.buildJPAQuery(JmixEclipseLinkQuery.java:557)
    at io.jmix.eclipselink.impl.JmixEclipseLinkQuery.getQuery(JmixEclipseLinkQuery.java:467)
    at io.jmix.eclipselink.impl.JmixEclipseLinkQuery.getResultList(JmixEclipseLinkQuery.java:134)

jmix-trainings-working-with-data-advanced.zip


Jmix 2.1 test required (https://github.com/jmix-framework/jmix/issues/1721)

gorbunkov commented 4 months ago

Should be ported to 1.x

KartnDev commented 4 months ago

Won't fix.

After research, i did conclusion. There is too much changes to support entity and it's value in different datasources(databases). Right now, dynamic attribute add-on is tailored to the use of a single database. We can't place dynAttrValue entity and target entity in several databases without any hurt.

KartnDev commented 4 months ago

New feature that fix this: https://github.com/jmix-framework/jmix/issues/2963

KartnDev commented 4 months ago

Feature request:

Support working with different databases inside dynamic attribute

Current behaviour:

Right now, whole Dynamic Attribute add-on designed for single database. We need to redesign add-on so that can work with different databases. E.g.

Entity -> Primary DB DynamicAttributeValue (entity) -> Secondary DB DynamicAttributeValue.value (for example Entity has dynamic field that entity field too) -> Tertiary DB

And that should works

KartnDev commented 2 months ago

UPD: Current behaviour

  1. Entity link won't work when reference refers to the entity which located in other datasource.
  2. If "Dynamic attributed" entity located "not primary database" and it's attribute refers to the primary datasource entity - all fine and works.

Conclusions

  1. Dynamic attributes still working with any of entity that located in any of datasource
  2. If you want to refer the entity dynamically, you need to sure that CategoryAttributeValue entity located in same datasource neither do your target dynamic "Referred" entity.