Creating referencing entities (Jmix)

79 Views Asked by At

I have a successor to the User entity - the client. It is referenced by the Type entity. When I load the application and try to create a new type, I select the client to which I want to bind the type, but an error appears that such a client already exists, although I do not create a client, but select an existing one.

package com.company.perfect_project.entity;

import io.jmix.core.metamodel.annotation.JmixEntity;

import javax.persistence.Entity;

@JmixEntity
@Entity(name = "Client_")
public class Client extends User {

}

Type Entity

package com.company.perfect_project.entity;

import io.jmix.core.metamodel.annotation.JmixEntity;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

@JmixEntity
@Table(name = "TYPE_", uniqueConstraints = {@UniqueConstraint(columnNames = {"NAME", "CLIENT"})})
@Entity(name = "Type_")
public class Type {

    @Id
    @Column(name = "ID", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column(name = "NAME")
    @NotNull
    private String name;

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "USER_ID")
    @NotNull
    private Client client;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Client getClient() {
        return client;
    }

    public void setClient(Client client) {
        this.client = client;
    }
}

type-edit.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://jmix.io/schema/ui/window"
        caption="msg://typeEdit.caption"
        focusComponent="form">
    <data>
        <instance id="typeDc"
                  class="com.company.perfect_project.entity.Type">
            <fetchPlan extends="_base">
                <property name="client" fetchPlan="_instance_name"/>
            </fetchPlan>
            <loader/>
        </instance>
    </data>
    <facets>
        <dataLoadCoordinator auto="true"/>
        <screenSettings id="settingsFacet" auto="true"/>
    </facets>
    <actions>
        <action id="windowCommitAndClose" caption="msg:///actions.Ok"
                icon="EDITOR_OK"
                primary="true"
                shortcut="${COMMIT_SHORTCUT}"/>
        <action id="windowClose"
                caption="msg:///actions.Close"
                icon="EDITOR_CANCEL"/>
    </actions>
    <dialogMode height="600"
                width="800"/>
    <layout spacing="true" expand="editActions">
        <form id="form" dataContainer="typeDc">
            <column width="350px">
                <textField id="nameField" property="name"/>
                <entityPicker id="clientField" property="client">
                    <actions>
                        <action id="entityLookup" type="entity_lookup"/>
                        <action id="entityClear" type="entity_clear"/>
                    </actions>
                </entityPicker>
            </column>
        </form>
        <hbox id="editActions" spacing="true">
            <button id="commitAndCloseBtn" action="windowCommitAndClose"/>
            <button id="closeBtn" action="windowClose"/>
        </hbox>
    </layout>
</window>

where is the problem?

I use Java 17 and JMix 1.1.4, my idea can’t found newer versions, i don’t know why.

0

There are 0 best solutions below