嵌套异常是 org.hibernate.MappingException:无法确定类型:Com.test.model.Client,在 table:ComptePaiement

nested exception is org.hibernate.MappingException: Could not determine type for: Com.test.model.Client, at table: ComptePaiement

我在我的 spring 项目中使用 Hibernate。但它不适用于一对一关系。它给了我以下错误。

Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not determine type for: com.example.TransfertNational.model.Client, at table: ComptePaiement, for columns: [org.hibernate.mapping.Column(client)]

我在互联网上 运行 进行了一些搜索,但它对我不起作用。

客户端实体:

@Data @Entity
@AllArgsConstructor @NoArgsConstructor @ToString
public class Client {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    private String typeTransfert;
    private String typePiece;
    private String cin;

    private String sexe;
    private String prenom;
    private String typePieceIdentite;
    private String paysEmission;
    private String numPI;
    private String validitePI;
    private String dateNaissance;
    private String profession;
    private String nationalite;
    private String paysAdresse;
    private String adresseLegale;
    private String ville;
    private String gsm;
    private String email;
    @OneToMany(fetch = FetchType.LAZY,
            cascade = CascadeType.ALL)
    private Set<Beneficiaire> beneficiares;
    @OneToOne(fetch = FetchType.LAZY,
            cascade = CascadeType.ALL)
    private ComptePaiement comptePaiement;
}

ComptePaiement 实体:

@Data
@Entity
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class ComptePaiement {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    private String solde;
    private String rip;
    private Client client;
}

来自评论的回答:

您可能在 ClientComptePaiement@OneToOne 注释中缺少 @JoinColumnmappedBy,具体取决于哪个将在数据库中保存引用 ID。