Hi,
You can create to_one association using Studio.
In my test application, I have an entity with Composite PK of three columns in additional datastore. Studio has generated the link to the entity as follows:
Is this possible with Cuba? What should I put instead of ??? to let Cuba know that, for example, Person’s Id should be placed to id.personId and respectively Speciality’s Id - to id.specialityId?
If I specify:
@Transient
@MetaProperty(related = "personId")
protected Person person;
then Cuba throws the following exception in browse screen for Reviewer entity:
com.haulmont.cuba.core.global.RemoteException: Property 'personId' not found in asdf$Reviewer
Hi,
Let me bring an example of how an entity with composite PK could be created.
Composite PK entities are represented by two entities:
EmbeddableEntity which consists of PK - fields.
@NamePattern("%s %s|keyOne,keyTwo")
@MetaClass(name = "formattertest$KeyEntity")
@Embeddable
public class KeyEntity extends EmbeddableEntity {
private static final long serialVersionUID = -6154461586339023936L;
@Column(name = "KEY_ONE")
protected String keyOne;
@Column(name = "KEY_TWO")
protected String keyTwo;
...
BaseGenericIdEntity with embedded ID
@NamePattern("%s|utilityField")
@Table(name = "FORMATTERTEST_CPK_ENTITY")
@Entity(name = "formattertest$CPKEntity")
public class CPKEntity extends BaseGenericIdEntity<KeyEntity> {
private static final long serialVersionUID = -6805482344993664086L;
@EmbeddedId
protected KeyEntity id;
@Column(name = "UTILITY_FIELD")
protected String utilityField;
@Override
public KeyEntity getId() {
return id;
}
@Override
public void setId(KeyEntity id) {
this.id = id;
}
....
You can create and setup such Composite_PK_Entity by Studio. Using Studio, you can associate the entity with others by any type of association. You can create screens for it. Everything should work well. For “imported” entities (created during model generation) - too.
So it seems there is no need to make the properties @Transient and bind them programmatically.
When the entity is in additional datastore only links to it are allowed as Studio must not modify additional datastore scheme. The link is created in that case as were described in my previous post.