jmix-projects / jmix-ui

DEPRECATED. Use https://github.com/jmix-framework/jmix
https://www.jmix.io
3 stars 7 forks source link

TagField does not work correctly if Entity has field with Set type #610

Closed Flaurite closed 3 years ago

Flaurite commented 3 years ago

Description

  1. Create entities with association one to many. Select Set type for collection field.
  2. Add TagField to the editor, for instance:
    <tagField id="tagPicker"
          dataContainer="veterinarianDc"
          property="specialties">
       <query entityClass="io.jmix.petclinic.entity.veterinarian.Specialty"
                    escapeValueForLike="true"
                    searchStringFormat="%${searchString}%">
              <![CDATA[select e from petclinic_Specialty e where lower(e.name) like lower(:searchString) escape '\']]>
       </query>
    </tagField>
  3. Add some values to the TagField and try to save entity.

AR

Caused by: java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class java.util.Set (java.util.ArrayList and java.util.Set are in module java.base of loader 'bootstrap')
    at io.jmix.core.metamodel.model.utils.MethodsCache$SettersHolder.accept(MethodsCache.java:188) ~[jmix-core-1.0.0.jar:na]
    at io.jmix.core.entity.BaseEntityEntry.setAttributeValue(BaseEntityEntry.java:104) ~[jmix-core-1.0.0.jar:na]
    at io.jmix.core.entity.EntityValues.setValue(EntityValues.java:73) ~[jmix-core-1.0.0.jar:na]
    at io.jmix.core.entity.EntityValues.setValueEx(EntityValues.java:198) ~[jmix-core-1.0.0.jar:na]
    at io.jmix.core.entity.EntityValues.setValueEx(EntityValues.java:151) ~[jmix-core-1.0.0.jar:na]
    at io.jmix.ui.component.data.value.ContainerValueSource.setValue(ContainerValueSource.java:170) ~[jmix-ui-1.0.0.jar:na]
    at io.jmix.ui.component.data.value.ValueBinder$ValueBindingImpl.setValueToSource(ValueBinder.java:316) ~[jmix-ui-1.0.0.jar:na]
    at io.jmix.ui.component.data.value.ValueBinder$ValueBindingImpl.componentValueChanged(ValueBinder.java:309) ~[jmix-ui-1.0.0.jar:na]
    at io.jmix.core.common.event.EventHub.publish(EventHub.java:170) ~[jmix-core-1.0.0.jar:na]
    at io.jmix.ui.component.impl.AbstractComponent.publish(AbstractComponent.java:85) ~[jmix-ui-1.0.0.jar:na]
    at io.jmix.ui.component.impl.AbstractValueComponent.componentValueChanged(AbstractValueComponent.java:154) ~[jmix-ui-1.0.0.jar:na]
    at io.jmix.ui.component.impl.AbstractField.lambda$attachValueChangeListener$ab1c93c8$1(AbstractField.java:145) ~[jmix-ui-1.0.0.jar:na]

QA

  1. Create two entities with one-to-many association;
  2. Use Set collection type;
  3. Add TagField to the editor and try to select some values, for instance:
    <tagField id="orderLinesField" property="orderLines">
    <query entityClass="com.company.app.entity.OrderLine"
           escapeValueForLike="true"
           searchStringFormat="%${searchString}%">
        <![CDATA[select e from OrderLine e where e.name like :searchString escape '\']]>
    </query>
    </tagField>
  4. Save entity - there is no exception should occur.
  5. Try to use #setTagComparator. No exception should occur.

Another case try to change collection type to List and try to edit entity's collection field. No exception should occur.