'foreign key does not exists in another table but it saved (Spring boot )

i have a many-to-many relationship and when i run the project and pass the foreign key for saving to middle table, it doesn't check if exists and it saved without any object in other table . could you please help me ?

@Entity
@Data
@Table(name = "warehouses")
public class Warehouse {
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    @Column(name = "id",nullable = false)
    private long id;

    @OneToMany(mappedBy = "warehouse")
    private List<WarehouseUser> warehouseUsers;
}


@Entity
@Data
@Table(name = "warehouse_users")
public class WarehouseUser {
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    @Column(name = "id",nullable = false)
    private long id;

    @Column(name = "warehouse_id", insertable = false , updatable = false)
    private long warehouseId;

    @ManyToOne
    @JoinColumn(referencedColumnName = "id", nullable = false)
    private Warehouse warehouse;


}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source