Relationship between classes Composite key error: not Mapped to a single Property

Asked

Viewed 163 times

2

I have a Cvariacaoto class that has a composite key (FK_T, FK_F, FK_F_VARIACAO). Two of these primary key fields (FK_F, FK_F_VARIACAO) are also foreign key to the Fvariacaoto table, in a Manytoone relationship

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
    @JoinColumn(name = "FK_F", referencedColumnName = "FK_F", nullable = false, insertable = false, updatable = false),
    @JoinColumn(name = "FK_F_V", referencedColumnName = "ID", nullable = false, insertable = false, updatable = false) })
@NotNull
private FVariacaoTO fVariacaoTO;

The class Fvariacaoto has two primary keys, which are being referenced, within a class Fvariacaopk.

I’m getting the following error: referencedColumnNames(FK_F, ID) by Cvariacaoto.fVariacaoTO not Mapped to a single Property

What normally causes this error? How can I resolve this relationship?


EDIT: Additional Information.

In the Fvariacaoto class, the key is @Embeddedid, as follows:

@EmbeddedId @AttributeOverrides({ @AttributeOverride(name = "fkF", column = @Column(name = "fkF", nullable = false)), @AttributeOverride(name = "id", column = @Column(name = "id", nullable = false)) }) @NotNull private FVariacaoPK fVariacaoPK;

And in the Fvariacaopk class, which has this ID indicated on @Embeddedid, it looks like this:

@Column(name = "FK_F", nullable = false) private int fkF;

@Column(name = "ID", nullable = false) private int id;
  • Your question is complicated to understand, it tries to put the error that is occurring and its cause, along with the classes with code formatting. This makes it difficult to help you. But this error occurs when you are setting the id of a map more than once. When subscribing to an id is required use @Attributeoverride(name="id",column=@Column(name="NOVA_ID"))

1 answer

0


I haven’t been able to run the application yet because there are other problems to be solved, but by doing so the compiler stopped complaining about this issue:

@JoinColumn(name = "FK_F", referencedColumnName = "fkF", nullable = false, insertable = false, updatable = false), @JoinColumn(name = "FK_F_V", referencedColumnName = "id", nullable = false, insertable = false, updatable = false)

I indicated in referencedColumnName the name of the field in the referenced entity, Fvariacaoto, and not in the object @Embedabble Fvariacaopk, as I was doing

Although he did not fully understand the situation, the problem was no longer charged.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.