I was created code for simple rest api , and I configure many to many relationship with two entity classes and I want to know how to write addContract method with also filling its related room and contractroom tables below are my code and I want some help, please

contract class

```
@Entity
@Table(name = "T475_Contract")
public class  Contract implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "contractId")
    private long contractId;

    @Column(name="start_date")
    private Date st_date;

    @Column(name="end_date")
    private Date end_date;

    @ManyToOne(fetch = FetchType.EAGER, optional = false)
    @JoinColumn(name = "hotel_id", nullable = false)
    @OnDelete(action = OnDeleteAction.CASCADE)
    /*@JsonIgnore*/
    private Hotel hotel;

    @OneToMany(
            mappedBy = "contract",
            cascade = CascadeType.ALL,
            orphanRemoval = true
    )
    private List<ContractRoom> rooms = new ArrayList<>();

    public Contract(){}

    public Contract(Date st_date, Date end_date) {
        this.st_date = st_date;
        this.end_date = end_date;
    }

//getters and setters

public void addRoom(Room room, int roomCount, double roomPrice){
    ContractRoom contractRoom = new ContractRoom(this,room, roomCount, roomPrice);
    rooms.add(contractRoom);
    room.getContracts().add(contractRoom);
}

public void removeRoom(Room room){
    for(Iterator<ContractRoom> iterator = rooms.iterator();
    iterator.hasNext();
    ){
        ContractRoom contractRoom = iterator.next();
        if(contractRoom.getContract().equals(this) && contractRoom.getRoom().equals(room)){
            iterator.remove();
            contractRoom.getRoom().getContracts().remove(contractRoom);
            contractRoom.setContract(null);
            contractRoom.setRoom(null);
        }
    }
}
}

```

my room class

```
@Entity
@Table(name="T475_Room")
@NaturalIdCache
@Cache(
       usage =  CacheConcurrencyStrategy.READ_WRITE
)
public class Room implements Serializable {
    @Id
    @NaturalId
    @Column(name="room_type")
    private String room_type;
    @Column(name="max_adults")
    private int max_adults;

    /*@Column(name="room_count")
    private int room_count;
    @Column(name="room_price")
    private double room_price;*/

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "hotel_id", nullable = false)
    @OnDelete(action = OnDeleteAction.CASCADE)
    /*@JsonIgnore*/
    @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
    private Hotel hotel;

    @OneToMany(
            mappedBy = "room",
            cascade = CascadeType.ALL,
            orphanRemoval = true
    )
    private List<ContractRoom> contracts = new ArrayList<>();

    public Room(){}

    public Room(String room_type, int max_adults) {
        this.room_type = room_type;
        this.max_adults = max_adults;
    }

}

```

my ContractRoom class

```
@Entity
@Table(name = "T475_ContractRoom")
public class ContractRoom {

@EmbeddedId
private ContractRoomId id;

@ManyToOne(fetch = FetchType.LAZY)
@MapsId("contractId")
private Contract contract;

@ManyToOne(fetch = FetchType.LAZY)
@MapsId("room_type")
private Room room;

@Column(name="room_count")
private int room_count;

@Column(name="room_price")
private double room_price;

private ContractRoom() {}

public ContractRoom(Contract contract, Room room, int room_count, double room_price) {
    this.contract = contract;
    this.room = room;
    this.room_count = room_count;
    this.room_price = room_price;
    this.id = new ContractRoomId(contract.getContractId(),room.getRoom_type());
}
//Getters and setters 

}

```

I want to write the method for saving contract in a database with related contractRoom and room objects in service class how can I write that?