Entities with a many-to-one relationship, not by primary key

Hello, I’m newbie in this, so there are questions in the description of the relationship between entities! How do I correctly describe the connection that is shown in the diagram:

image

I tried this way:


@Table(name = "TABLE_2")
@Entity(name = "TABLE2")
public class Table2 {
    @Id
    @Column(name = "TBL_2_ID")
    private Long tbl2_id;
    
    @OneToMany(mappedBy = "tbl2")
    private List<Table1> tables;

    @Column(name = "CODE")
    private String code;

    ...
}

@Table(name = "TABLE_1")
@Entity(name = "TABLE1")
public class Table1 {
    @Id
    @Column(name = "TBL_1_ID")
    private Long  tbl_id;
    
    @manyToOne(fetch = FetchType.LAZY)
    @joinColumn(name = "TBL_2", referencedColumnName = "CODE")
    private Table2 tbl2;

     ...
}

But as a result, the application started reporting that entities were incorrectly described.

Please help me to solve this problem

What exactly error message do you get?
Also, please reproduce your case on a small demo project and attach it here.

I tried different ways to describe the relationship using examples from the Internet. But if we are talking about the example that I gave, then when trying to open the form where i use Table1 entity, it gives a message that it did not find the column “TABLE_1_TBL_1_ID” in “TABLE_2”.