Why is one related entity displayed and the other not?

I have the following entity: CardItem

@NamePattern("The document in the following state: %s|cardState")
@Table(name = "DEMO_CARD_ITEM")
@Entity(name = "demo$CardItem")
public class CardItem extends StandardEntity {
	private static final long serialVersionUID = -3956149009965224251L;

	@Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="ID")
    public UUID getId() { 
    	return id; 
    }
	
	@ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CARD_TYPE_ID")
    protected CardType cardType;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CARD_SUB_TYPE_ID")
    protected CardSubType cardSubType;
    
    @Column(name = "CARD_STATE", nullable = true)
    protected String cardState; 
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "CARD_CREATION_DATE", nullable = false)
    protected Date cardCreationDate = new Date();
    
    @Column(name = "CARD_OUTCOME_NUMBER", nullable = false)
    protected String cardOutcomeNumber;
    
    @Column(name = "CARD_DATE", nullable = false)
    protected Date cardDate;

    @Column(name = "CARD_ORGANIZATION", nullable = false)
    protected String cardOrganization;

    @Column(name = "CARD_DELIVERY_METHOD", nullable = false)
    protected String cardDeliveryMethod;

    @Column(name = "CARD_ADDITIONAL_INFORMATION", nullable = true)
    protected String cardAdditionalInformation;
    
    @Column(name = "REGISTRATOR_NAME")
    protected String registratorName;
    
	public String getCardState() {
		return cardState;
	}

	// SKIPPED

Entity CardType:

@NamePattern("Тип входящего документа: %s |b")
@Table(name = "DEMO_CARD_TYPE")
@Entity(name = "demo$CardType")
@Access(value = AccessType.FIELD)
public class CardType extends StandardEntity {
	private static final long serialVersionUID = -2234911097509892559L;

	@Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="ID")
    public UUID getId() { 
    	return id; 
    }
	
    @Column(name = "CARD_TYPE_ITEM", nullable = false)
    @Access(value = AccessType.FIELD)
    protected Integer a;
    
    @Column(name = "CARD_TYPE_NAME", nullable = false)
    @Access(value = AccessType.FIELD)
    protected String b;

	// SKIPPED

Entity CardSubType:

@NamePattern("Подтип входящего документа: %s |a")
@Table(name = "DEMO_CARD_SUB_TYPE")
@Entity(name = "demo$CardSubType")
@Access(value = AccessType.FIELD)
public class CardSubType extends StandardEntity {
	private static final long serialVersionUID = -3558412722346178348L;

	@Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="ID")
    public UUID getId() { 
    	return id; 
    }
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CARD_TYPE_ID")
    protected CardType cardType;

    @Column(name = "CARD_TYPE_NAME", nullable = false)
    @Access(value = AccessType.FIELD)
	protected String a;

    @Column(name = "CARD_TYPE_ITEM", nullable = false)
    @Access(value = AccessType.FIELD)
	protected Integer b;

	// SKIPPED

Descriptor card-item-edit.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        caption="msg://editCaption"
        class="com.client.web.item.CardItemEdit"
        datasource="cardItemDs"
        focusComponent="cardItemsGroup"
        lookupComponent="cardItemsGroup"
        messagesPack="com.client.web.item">
    
     <dsContext>
        <datasource id="cardItemDs" class="com.client.entity.CardItem" view="_local"/>
        	<collectionDatasource id="cardTypeDs" class="com.client.entity.CardType">
            <query>
                <![CDATA[select e from demo$CardType e]]>
            </query>
        </collectionDatasource>
        	<collectionDatasource id="cardSubTypeDs" class="com.client.entity.CardSubType">
            <query>
                <![CDATA[select s from demo$CardSubType s where s.cardType.id = :ds$cardTypeDs]]>
            </query>
        </collectionDatasource>
    </dsContext>
    
    <actions>
        <action id="save" caption="mainMsg://actions.Ok" invoke="save" />
        <action id="cancel" caption="mainMsg://actions.Cancel" invoke="cancel" />
    </actions>
    
    <dialogMode forceDialog="true" width="AUTO"/>
	<layout spacing="true">
        <fieldGroup id="cardItemsGroup" datasource="cardItemDs">
            <column width="500px">
                <field id="cardCreationDate" property="cardCreationDate" editable="false" datasource="cardItemDs" />
                <field id="cardTypeField" caption="Тип документа">
            		<lookupPickerField id="cardType" datasource="cardItemDs" property="cardType" optionsDatasource="cardTypeDs"/>
				</field>
                <field id="cardSubTypeField" caption="Подтип документа">
                	<lookupPickerField id="cardSubType" datasource="cardItemDs" property="cardSubType" optionsDatasource="cardSubTypeDs"/>
				</field>
                <field id="cardOutcomeNumber" datasource="cardItemDs" property="cardOutcomeNumber"/>
                <field id="cardDate" datasource="cardItemDs" property="cardDate"/>
                <field id="cardOrganization" datasource="cardItemDs" property="cardOrganization"/>
                <field id="cardDeliveryMethod" datasource="cardItemDs" property="cardDeliveryMethod"/>
                <field id="cardAdditionalInformation" datasource="cardItemDs" property="cardAdditionalInformation"/>
                <field id="registratorName" datasource="cardItemDs" property="registratorName"/>
            </column>
        </fieldGroup>
		<hbox id="actionsPane" spacing="true" visible="true">
			<button id="saveBtn" action="save"/>
			<button id="cancelBtn" action="cancel"/>
		</hbox>
    </layout>
</window>

Controller CardItemEdit:

public class CardItemEdit extends AbstractEditor<CardItem> {
	
	@Inject
	private CollectionDatasource<CardItem, UUID> departmentCollectionDs;
	
    @Inject
    private Datasource<CardItem> departmentDs;
	
	@Named("cardItemsGroup.cardCreationDate")
    private Field cardCreationDate;
    
	@Inject
    private LookupField cardType;
    @Inject
    private LookupField cardSubType;
    
    @Named("cardItemsGroup.cardOutcomeNumber")
    private Field cardOutcomeNumber;
    
    @Named("cardItemsGroup.cardDate")
    private Field cardDate;
    
    @Named("cardItemsGroup.cardOrganization")
    private Field cardOrganization;
    
    @Named("cardItemsGroup.cardDeliveryMethod")
    private Field cardDeliveryMethod;
    
    @Named("cardItemsGroup.cardAdditionalInformation")
    private Field cardAdditionalInformation;
    
    @Named("cardItemsGroup.registratorName")
    private Field registratorName;

    @Inject
    private CardItemService cardItemService;
    
    public void save() {
    	CardItem cardItem = new CardItem();
    	cardItem.setCardType(cardType.getValue());
    	cardItem.setCardSubType(cardSubType.getValue());
    	cardItem.setCardOutcomeNumber(cardOutcomeNumber.getValue());
    	cardItem.setCardOrganization(cardOrganization.getValue());
    	cardItem.setCardDeliveryMethod(cardDeliveryMethod.getValue());
    	cardItem.setCardDate(cardDate.getValue());
    	cardItem.setCardCreationDate(cardCreationDate.getValue());
    	cardItem.setCardAdditionalInformation(cardAdditionalInformation.getValue());
    	cardItem.setRegistratorName(registratorName.getValue());
    	
    	cardItemService.saveCardItem(cardItem);
    }
}

Descriptor card-item-browse.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        caption="msg://browseCaption"
        class="com.client.web.item.CardItemBrowse"
        focusComponent="documentsTable"
        lookupComponent="documentsTable"
        messagesPack="com.client.web.item">
    <dsContext>
        <collectionDatasource id="cardItemDs" class="com.client.entity.CardItem" view="card-item-browse">
            <query>
                <![CDATA[select c from demo$CardItem c]]>
            </query>
        </collectionDatasource>
    </dsContext>
    
    <layout expand="documentsTable" spacing="true">
        <filter id="filter" applyTo="documentsTable" datasource="cardItemDs">
            <properties include=".*"/>
        </filter>
        
        <table id="documentsTable" width="100%">
            <actions>
                <action id="create"/>
                <action id="remove"/>
			</actions>
        
            <columns>
                <column id="cardState"/>
                <column id="cardType"/>
                <column id="cardSubtype"/>
                <column id="cardOutcomeNumber"/>
                <column id="cardDate"/>
                <column id="cardOrganization"/>
                <column id="cardDeliveryMethod"/>
                <column id="cardAdditionalInformation"/>
                <column id="registratorName"/>
            </columns>
            <rows datasource="cardItemDs"/>
            <rowsCount/>
            <buttonsPanel id="buttonsPanel" alwaysVisible="true">
                <button id="createBtn" action="documentsTable.create"/>
                <button id="removeBtn" action="documentsTable.remove"/>
            </buttonsPanel>
			</table>        	
		</layout>
</window>

views.xml:

<views xmlns="http://schemas.haulmont.com/cuba/view.xsd">
  <view class="com.client.entity.CardItem"
        name="card-item-browse"
        extends="_local">
      <property name="cardType"/>
      <property name="cardSubType"/>
  </view>
</views>

What is the problem. I can create a new instance of CardItem and it will be saved in the database. When creating a CardItem, I can choose the type(CardType) and subtype(CardSubType) of the document:

screen-02

I see that everything has been saved correctly in the database, but in the table, in the card-item-browse I don’t see the subtype(CardSubType):

screen-01

What could be the reason?

I would be very grateful for the information. Thanks to all.

Hi Aleksey,

The reason is just a misprint here:

<column id="cardSubtype"/>

Replace cardSubtype with cardSubType, and it should work.

2 Likes

Hi, Olga!

Thank you very much for your answer!
You look perfect.

Kind regards.