admin管理员组

文章数量:1287526

I'm not even quite sure how to quickly word my question for a title, but what I'm attempting to do is: I have a tank entity that contains a list of RefLines. There is also a list of tests which each contain parameter inside. What I'm trying to do is link the refLine to that parameter based on the foreign keys the refLine has (one to parameter and one to tank).

Example entry

line_id: 1 (pk)
param_id: 1 (fk)
tank_id: 1 (fk)
value: 10
color: red

I was originally thinking of placing a one to many in the parameter entity but I don't know how to link the tank_id from that to the tank itself so only the refLines for that tank exist within that list. I feel like I'm not making much sense but hopefully enough to get some help. I can add the controllers/services/repositories if needed but I'm not sure if it would help as I'm not having issues with the code yet, just trying to see if this is possible or if I have to do something weird to make it work.

I'm not even quite sure how to quickly word my question for a title, but what I'm attempting to do is: I have a tank entity that contains a list of RefLines. There is also a list of tests which each contain parameter inside. What I'm trying to do is link the refLine to that parameter based on the foreign keys the refLine has (one to parameter and one to tank).

Example entry

line_id: 1 (pk)
param_id: 1 (fk)
tank_id: 1 (fk)
value: 10
color: red

I was originally thinking of placing a one to many in the parameter entity but I don't know how to link the tank_id from that to the tank itself so only the refLines for that tank exist within that list. I feel like I'm not making much sense but hopefully enough to get some help. I can add the controllers/services/repositories if needed but I'm not sure if it would help as I'm not having issues with the code yet, just trying to see if this is possible or if I have to do something weird to make it work.

Share Improve this question asked Feb 24 at 5:59 TapialjTapialj 3452 gold badges3 silver badges11 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

IIUC the relations between your entities are:
1 tank to many reflines, 1 refline to 1 param.
in that case the refline entity should be

public class RefLine {

    @Id
    private int lineId;

    @OneToOne
    @JoinColumn(name = "param_id", referencedColumnName = "id")
    private Param param;

    @ManyToOne
    @JoinColumn(name = "tankId", insertable = false, updatable = false)
    private Tank tank;
    ...

本文标签: javaTrying to figure out how to joinlink 3 different spring boot entitiesStack Overflow