'One of composite primary key as foreign key

I have below composite primary key in class below

  @Entity(name="data_req_id")
    @IdClass(Composite.class)
    public class DataRequestId{
    
      @Id
      @ManyToOne
      @JoinColumn(name="request_id")
      Request request;
      
     @Id
     String someId;
    }

public class Composite implements Serilizable{
     private Request request;
     private String someId;
     Composite(Request request, String someId){
          this.request =  request;
          this.someId = someId
   }
}

below is my request class:

@Entity
@DynamicUpdate
public class Request{
 
   @Id
   int id;
   // some other attributes
   @OneToMany(cascade={CascadeType.PERSIST}, mappedBy = "request")
    List<DataRequestId> dataReqId;

}
}

I want to know this is correct approach? to keep one composite key as foreign key in other table?



Sources

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

Source: Stack Overflow

Solution Source