Hi,
I’m trying to relate two entities with composite keys in a legacy application,
but I’m not sure how to do it directly using studio.
I have two entities, Persons and Representatives, which in the legacy database (Oracle)
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.
Relationship with added fields and modification of getters and setters of entities
I am trying the following:
I have added the following fields marked with *
Person
idPerson(PK)
name
surnames
address
representative *
*Attribute type: Association
Type: Representative
Read only: No
Mandatory: No
Transient: Yes
Create field: Yes
Related attributes: idPersona
Collection type: List
Additionally, I have modified the GET of the entity using a function that returns a person, as follows:
public List<Representative> getRepresentatives() {
return AppBeans.get(RepresentativeService.class).returnRepresentatives(idPerson);
}
Representative
id
name
surnames
address
person *
*Attribute type: Association
Type: Person
Read only: No
Mandatory: Yes
Transient: Yes
Create field: Yes
Related attributes: id
Collection type: (Blank because I have modified the get of the entity)
In this entity I have also modified the GET of the entity in the following way:
public Person getPerson() {
return AppBeans.get(PersonService.class).returnPerson(id.getIdPerson());
}
With these modifications I have achieved that on the Representative search screen
The related person information appears as configured in the view.
The problem appears when we want to edit the registry, which gives a Stack Overflow error.
I attach it below:
java.lang.StackOverflowError
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/jdk.internal.reflect.MethodAccessorGenerator.generate(MethodAccessorGenerator.java:393)
at java.base/jdk.internal.reflect.MethodAccessorGenerator.generateSerializationConstructor(MethodAccessorGenerator.java:112)
at java.base/jdk.internal.reflect.ReflectionFactory.generateConstructor(ReflectionFactory.java:514)
at java.base/jdk.internal.reflect.ReflectionFactory.newConstructorForSerialization(ReflectionFactory.java:506)
at java.base/java.io.ObjectStreamClass.getSerializableConstructor(ObjectStreamClass.java:1516)
at java.base/java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:509)
at java.base/java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:484)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.io.ObjectStreamClass.(ObjectStreamClass.java:484)
at java.base/java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:381)
at java.base/java.io.ObjectStreamClass.(ObjectStreamClass.java:480)
at java.base/java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:381)
at java.base/java.io.ObjectStreamClass.(ObjectStreamClass.java:480)
at java.base/java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:381)
at java.base/java.io.ObjectStreamClass.(ObjectStreamClass.java:480)
at java.base/java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:381)
at java.base/java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1135)
at java.base/java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:349)
at com.haulmont.cuba.core.sys.serialization.StandardSerialization.serialize(StandardSerialization.java:34)
…etc