Invalid item's metaclass

Hi all,

I have an entity (Suggestion) that has 3 fields which are all associations coming from the same other entity (User).

The fields for Suggestion are as follows:
recipient (association - user id)
suggestion (association - user id)
suggester (association - user id)

I am running into trouble in my view. There are a few behaviors that are wrong.

First, based on the number of rows fetched, it looks like it is fetching all existing Users instead of all existing Suggestions. The columns are “User.recipient”, “User.suggestion”, and “User.suggester”, which leads me to believe for some reason the loader thinks that it is loading User instances instead of Suggestion instances.

Second, when I click the “Create” button, I get the following error (I’ve masked the company name).

DevelopmentException: Invalid item's metaClass 'xxxxx_User'

container: InstanceContainerImpl{entity=xxxxx_Suggestion, view=com.xxxxx.xxxxx.entity.Suggestion/suggestion-view}
metaClass: xxxxx_User

This is my browse screen file:

<window xmlns="http://schemas.haulmont.com/cuba/screen/window.xsd"
        xmlns:c="http://schemas.haulmont.com/cuba/screen/jpql_condition.xsd"
        caption="msg://browseCaption"
        focusComponent="table"
        messagesPack="com.xxxxx.xxxxx.web.screens.suggestion">
    <data>
        <collection id="suggestionsDc"
                    class="com.xxxxx.xxxxx.entity.Suggestion"
                    view="suggestion-view">
            <loader id="suggestionsDl">
                <query>
                    <![CDATA[select e from xxxxx_Suggestion e]]>
                </query>
            </loader>
        </collection>
        <instance id="suggestionDc"
                  class="com.xxxxx.xxxxx.entity.Suggestion"
                  view="suggestion-view">
            <loader/>
        </instance>
        <collection id="recipientsDc" class="com.xxxxxx.xxxxxx.entity.User" view="_minimal">
            <loader id="recipientsDl">
                <query>
                    <![CDATA[select e from xxxxx_User e]]>
                </query>
            </loader>
        </collection>
        <collection id="suggestionsDc" class="com.xxxxx.xxxxxx.entity.User" view="_minimal">
            <loader id="suggestionsDl">
                <query>
                    <![CDATA[select e from xxxx_User e]]>
                </query>
            </loader>
        </collection>
        <collection id="suggestersDc" class="com.xxxxx.xxxxx.entity.User" view="_minimal">
            <loader id="suggestersDl">
                <query>
                    <![CDATA[select e from xxxxx_User e]]>
                </query>
            </loader>
        </collection>
    </data>
    <actions>
        <action id="save" icon="icons/ok.png" caption="mainMsg://actions.Ok" shortcut="CTRL-ENTER"/>
        <action id="cancel" icon="icons/cancel.png" caption="mainMsg://actions.Cancel" description="Esc"/>
    </actions>
    <dialogMode height="600" width="800"/>
    <layout>
        <split id="split" height="100%" orientation="horizontal" reversePosition="true" width="100%">
            <vbox id="lookupBox" expand="table" height="100%" margin="false,true,false,false" spacing="true">
                <filter id="filter" applyTo="table" dataLoader="suggestionsDl">
                    <properties include=".*"/>
                </filter>
                <groupTable id="table"
                            width="100%"
                            dataContainer="suggestionsDc">
                    <actions>
                        <action id="create" type="create"/>
                        <action id="edit" type="edit"/>
                        <action id="remove" type="remove"/>
                    </actions>
                    <columns>
                        <column id="recipient"/>
                        <column id="suggestion"/>
                        <column id="suggester"/>
                    </columns>
                    <rowsCount/>
                    <buttonsPanel id="buttonsPanel"
                                  alwaysVisible="true">
                        <button id="createBtn" action="table.create"/>
                        <button id="editBtn" action="table.edit"/>
                        <button id="removeBtn" action="table.remove"/>
                    </buttonsPanel>
                </groupTable>
                <hbox id="lookupActions" spacing="true" visible="false">
                    <button action="lookupSelectAction"/>
                    <button action="lookupCancelAction"/>
                </hbox>
            </vbox>
            <vbox id="editBox" height="100%" margin="false,false,false,true" expand="fieldGroupBox" spacing="true">
                <scrollBox id="fieldGroupBox">
                    <form id="form" dataContainer="suggestionDc">
                        <column width="250px">
                            <lookupPickerField id="recipientField" optionsContainer="recipientsDc"
                                               property="recipient"/>
                            <lookupPickerField id="suggestionField" optionsContainer="suggestionsDc"
                                               property="suggestion"/>
                            <lookupPickerField id="suggesterField" optionsContainer="suggestersDc"
                                               property="suggester"/>
                            <checkBox id="dismissedField" property="dismissed"/>
                        </column>
                    </form>
                </scrollBox>
                <hbox id="actionsPane" spacing="true" visible="false">
                    <button id="saveBtn" action="save"/>
                    <button id="cancelBtn" action="cancel"/>
                </hbox>
            </vbox>
        </split>
    </layout>
</window>

Hi,
You have two collection containers named with the same name - suggestionsDc.
One of them holds Suggestion, another one holds User. It is clear from the code snippet you’ve provided.

I would kindly suggest you to start creating meaningful IDs for your components, otherwise you will be constantly spending hours of time to debug stupid problems in your code. It’s error-prone to have suggestionsDc, suggestionDc, suggestionsDc, suggestersDc in one screen.

Thanks, I didn’t notice that the IDE had generated overlapping id’s based on my field names. Fixed the problem.