Hibernate parent child 1-to-1 relationship with child id in parent table

Viewed 14

This inserts the parent (vehicle) but doesn't insert anything into the child table. I'm new to hibernate, is there something wrong here or is my problem elsewhere?

@Entity
@Table(schema = "mydb", name = "vehicles")
@Data
public class Vehicles {

    @Id
    @Column(name = "idvehicle")
    private Long idVehicle;

    @Column(name = "color")
    private String color;

    @Column(name = "passengers")
    private Double passengers;

    // field idcar (fk) must have the idcar field (pk) of the child
    @OneToOne(cascade= CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
    @JoinColumn(name = "idcar", columnDefinition = "serial")
    private Car car;

}


@Entity
@Table(schema = "mydb", name = "cars")
@Data
public class Cars {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "idcar", columnDefinition = "serial")
    private Long idCar;

    @Column(name = "owner")
    private String owner;

}
0 Answers
Related