I have a situation where metadata.create seems to be returning the same object more than once. Here is the code:
@Subscribe("tblSchematicStateOmit.create")
private void onTblSchematicStateOmitCreate(Action.ActionPerformedEvent event) {
SchematicStateOmit stateOmit = metadata.create(SchematicStateOmit.class);
stateOmit.setSchematic(getEditedEntity());
stateOmitsDc.getMutableItems().add(dataContext.merge(stateOmit));
}
When a user adds a row to the table, we create the appropriate object and add it to the Data Container after initializing a foreign key field.
I have pressed the button twice in my interface. Here is what the debugger shows as the value of the collection:
As you can see, the same object Id has been returned twice. Note that the entity has a composite key called SchematicstateomitsCompKey. The composite key has two fields:
@Column(name = "SCHEMATICID", nullable = false)
private Long schematicid;
@Column(name = "STATEOMIT", nullable = false, length = 2)
private String stateomit;
and in SchematicStateOmit object:
@EmbeddedId
private SchematicstateomitsCompKey id;
@MapsId("schematicid")
@JoinColumn(name = "SCHEMATICID")
@ManyToOne(fetch = FetchType.LAZY)
private Schematic schematic;
public Schematic getSchematic() { return schematic; }
public void setSchematic(Schematic schematic) {
this.schematic = schematic;
this.id.setSchematicid(schematic.getId());
}
@Override
public SchematicstateomitsCompKey getId() {
return id;
}
@Override
public void setId(SchematicstateomitsCompKey id) {
this.id = id;
}
Is there a special way to create an entity with a composite key?
What else am I missing here?