gpt4 book ai didi

java - JPA实体怎么做

转载 作者:行者123 更新时间:2023-12-01 10:42:44 25 4
gpt4 key购买 nike

我有那些实体当我持久化 LotPaiement 实体时,我希望使用 LotPaiement id 更新 PaiementId 的 idLot 。这可能吗?我尝试使用 JoinColomn 和其他东西,但它不起作用。我希望有人有其他想法......

    @Entity
@Table(name = "XX", schema = "X")
public class LotPaiement implements Serializable {

@Transient
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID_LOT_PAIE_EXT", insertable = false)
private int id;

@Column(name = "NO_ORGA", nullable = false, length = 10)
private String noOrganisme;

@Column(name = "NO_FICH_BANQ", nullable = false, length = 10)
private String noFichierBanque;

@Column(name = "NOM_FICH_BANQ" ,nullable = false, length = 60 )
private String nomFichierBanque;

@Column(name = "DAT_PROD", nullable = false, length = 10)
private Date dateProdBanque;

@Column(name = "IND_ENCAI", nullable = false, length = 1)
@Convert(converter = CodeChoixJpaConverter.class)
private CodeChoix encaissee = CodeChoix.NON;

@Column(name = "COD_PROVEN", nullable = false, length = 1)
private String codeProvenance;

@Column(name = "NB_PAIE", nullable = false)
private int nombrePaiements;

@Column(name = "MONT_LOT_PAIE", nullable = false, precision = 12)
private BigDecimal montantPaiements;

@Column(name = "MONT_FRAIS_LOT_PAIE", nullable = false, precision = 12)
private BigDecimal montantFraisPaiements;

@Column(name = "NB_CORR", nullable = false)
private int nombreCorrections;

@Column(name = "MONT_CORR", nullable = false, precision = 12)
private BigDecimal montantCorrections;

@Column(name = "MONT_FRAIS_CORR", nullable = false, precision = 12)
private BigDecimal montantFraisCorrections;

@Column(name = "NO_USAG_CREA", length = 8)
private String noUsagerCreation;

@Column(name = "DAT_HRE_CREA", nullable = false, length = 26, insertable = false)
private Date dateHeureCreation;

@Column(name = "NO_USAG_MODIF", length = 8)
private String noUsagerModif;

@Column(name = "DAT_HRE_MODIF", nullable = false, length = 26, insertable = false)
private Date dateHeureModif;

@OneToMany(targetEntity = Paiement.class, mappedBy = "id.idLot", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<Paiement> paiements = new ArrayList<Paiement>();

还有这个

@Entity
@Table(name = "F_PAIEMENT_EXT" , schema = "PAX")
public class Paiement implements Serializable {

@Transient
private static final long serialVersionUID = 973636294796000052L;

@EmbeddedId
private PaiementId id;

@Column(name = "COD_TYP_TRANS", nullable = false, length = 1)
@Convert(converter = TypeTransactionJpaConverter.class)
private TypeTransaction codeTypeTransaction;

@Column(name = "NOM_PAYEUR", nullable = false, length = 50)
private String nomPayeur;

@Column(name = "REFERENCE_1", nullable = false, length = 50)
private String reference1;

@Column(name = "REFERENCE_2", length = 50)
private String reference2;

@Column(name = "MONT_PAIE", nullable = false, precision = 10)
private BigDecimal montantPaiement;

@Column(name = "MONT_FRAIS_PAIE", nullable = false, precision = 5)
private BigDecimal montantFrais;

@Column(name = "COD_TYP_ORIG", length = 1)
@Convert(converter = TypeOrigineJpaConverter.class)
private TypeOrigine codeTypeOrigine;

@Column(name = "NO_INST_FINA", nullable = false, length = 5)
private String noInstitutionFinanciere;

@Column(name = "NO_TRANSIT_INST", nullable = false, length = 5)
private String noTransitInstitution;

@Column(name = "NO_CENTRE_SERV", nullable = false, length = 2)
private String noCentreService;

@Column(name = "DAT_PAIE", nullable = false, length = 10)
private Date datePaiement;

@Column(name = "NO_USAG_CREA", length = 8)
private String noUsagerCreation;

@Column(name = "DAT_HRE_CREA", nullable = false, length = 26, insertable = false)
private Date dateHeureCreation;

@Column(name = "NO_USAG_MODIF", length = 8)
private String noUsagerModif;

@Column(name = "DAT_HRE_MODIF", nullable = false, length = 26, insertable = false)
private Date dateHeureModif;

这是可嵌入类

@Embeddable
public class PaiementId implements Serializable {

@Transient
private static final long serialVersionUID = -4993016053388314553L;

@Column(name = "ID_LOT_PAIE_EXT")
private int idLot;

@Column(name = "NO_LIGNE", nullable = false)
private int noLigne;

最佳答案

您的帖子被标记为“JPA”,因此您正在使用对象关系映射框架,其目的恰恰是帮助您摆脱愚蠢的 id 并将其替换为实际引用对象。

因此,您的字段不应该是 private int idLot;

应该是private LotPaiement lotPaiament;

当然,映射将不起作用,您需要按如下方式修复它:

@OneToMany(targetEntity = Paiement.class, mappedBy = "lotPaiament", 
cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<Paiement> paiements = new ArrayList<Paiement>();

关于java - JPA实体怎么做,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34364606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com