Join table between two independent entities

Hi,
I’m trying to make an application where you can see the production data of a company. I generated the entities I needed from an oracle database and for one of the two entities the framework generated me a Compkey class with two attributes. Also, the entities have no association with each other. Now I want to create a screen where you can view the data of two separate entities. I thought about creating a screen from one of the two entities and doing an inner join with the other but it gives me an error.
Also, I tried to use this model (two-entities-one-table.zip )(90.9 KB) as an example, but here too it gives me an error.
How can I solve the problem ?

An example of a query that I tried to insert:

select p.codice_prodotto, p.descrizione, r.id.id_linea
from table1 p inner join table2 r
on p.codice_prodotto = r.id.cod_prodotto

Hi!
Unfotrunatelly I failed to install attached model because of ‘Unsupported CUBA Version’ error
Could you please attach a small sample project along with reproduction scenario that demonstrates the issue?

Hi!
I`ve opened the project on 6.10.3 studio, opened screen without errors and correct data was been displayes. Please attach error text

BR, Yuliya Maistrenko

Hi,
it’s a bit complicated to demo the project I’m making. I try to explain it to you.
What I want to do is generate a screen that shows a table made up of product code, idLinea, product description. I created a composition @OnetoMany in the Lines entity and @ManyToOne in the Products entity. Also, the Lines entity has two primary keys Product_Code and Line ID.

These are some attributes of the Lines entity:

@EmbeddedId
private AnagrafichedibaseCompKey id;

@Composition
@OneToMany(mappedBy = "line")
private List<AnagraficheProdo> product;

And these are some attributes of the Products entity:

@Id
@Column(name = "\"CODE_PRODUCT\"", nullable = false, length = 10)
private String codeProduct;
@Lookup(type = LookupType.DROPDOWN, actions = "lookup")
@JoinColumns({
        @JoinColumn(name = "LINE_\"CODE_PRODUCT\"", referencedColumnName = "\"CODE_PRODUCT\""),
        @JoinColumn(name = "LINE_\"ID_LINE\"", referencedColumnName = "\"ID_LINE\"")
})
@ManyToOne(fetch = FetchType.LAZY)
private Anagrafichedibase line;

This is the class that was generated automatically when I imported the entities from the database:

    @MetaClass(name = "mdr_AnagrafichedibaseCompKey")
    @Embeddable
    public class AnagrafichedibaseCompKey extends EmbeddableEntity {
      private static final long serialVersionUID = 6463136906075654234L;

      @Column(name = "\"CODE_PRODUCT\"", nullable = false, length = 10)
      private String codProduct;

      @Column(name = "\"ID_LINE\"", nullable = false, length = 3)
      private String idLine;

When I try to generate a screen browser and add the column line.id.idLine , this is the error it gives me:

IllegalStateException: Cannot get unfetched attribute [line] from detached object com.company.mdr.entity.anagrafica.AnagraficheProdo-51720831 [detached].

Hi,
We will be able to suggest a solution if you make a small test project with your data model.
Please use simple names for entities, HSQL or PostgreSQL database and the latest CUBA 6.10 or 7.2.

Regards,
Konstantin

Hi,

I am having the same problem.

I have two entities, Persons and Representatives, which in the database are related 1 to N through a foreign key.

Person
IdPerson(PK)
Name
Surnames
Address

Representative
IdPerson(PK)
IdRepresentative(PK)
Name
Surnames

When Cuba Platform reads the tables and creates the entities, it generates the two entities plus the composite key class for Representatives.

Person
idPersona(PK)
name
surnames
address

Representative
id(CompKey idPerson+idRepresentative, not linkable)
name
surnames
address

RepresentativeCompKey
idPerson
idRepresentative

I don’t know how to create the 1 to N relationship between Person and Representative since it is not possible to make the relationship directly.
And if I create the relationship using the CompKey when I run the application, it gives the error:

“Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.7.3.19-cuba): org.eclipse.persistence.exceptions.EntityManagerSetupException”

My intention is to be able to show on a screen all the representatives that a Person has and be able to add and remove them on that same screen.

Is there a standard way to do this?

Thank you in advance.