【问题标题】:nested exception is org.hibernate.MappingException: Could not determine type for: Com.test.model.Client, at table: ComptePaiement嵌套异常是 org.hibernate.MappingException:无法确定类型:Com.test.model.Client,在表:ComptePaiement
【发布时间】:2022-01-12 14:09:55
【问题描述】:

我在我的春季项目中使用 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;
}

【问题讨论】:

  • 您是否尝试过在Client 中的@OneToOne 上设置属性mappedBy?我认为您还需要在ComptePaiement 中的Client 属性上使用@OneToOneJoinColumn
  • 我将 @JoinColumn(name = "comptePaiement_id", referencedColumnName = "id") 添加到客户端实体并从 ComptePaiement 实体中删除了客户端变量,它工作正常,谢谢
  • 好的,我会作为答案。

标签: spring spring-boot hibernate spring-data-jpa


【解决方案1】:

来自cmets的回答:

您可能在ClientComptePaiement 上缺少@JoinColumn@OneToOne 注释中的mappedBy,这取决于数据库中的引用ID。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-06
    • 2020-01-03
    • 1970-01-01
    • 2014-11-29
    • 1970-01-01
    • 2016-05-23
    相关资源
    最近更新 更多