[英]Caused by: java.sql.SQLException: Subquery returns more than 1 row on all rows where emailAccess is thesame
[英]Caused by: java.sql.SQLException:The column name is specified more than once in the SET clause
將數據持久保存到表時,我面臨以下問題。
錯誤:
原因:java.sql.SQLException:在SET子句中多次指定了列名“ SubFundId”。 一列不能在同一SET子句中分配多個值。 修改SET子句以確保列僅更新一次。 如果SET子句更新視圖的列,則列名“ SubFundId”可能在視圖定義中出現兩次。
我用於持久存儲數據的代碼是:
@Transactional
public FundSalesCreditCalcMethodDTO addNewSubFundCalculationMethod(FundSalesCreditCalcMethodDTO dto) {
try{
@SuppressWarnings("unchecked")
List<Object> id = entityManager.createNamedQuery("findSelectedSubFund").setParameter("subFundId",dto.getSubFundId()).getResultList();
System.out.println("*********in addNewSubFundCalculationMethod " +id.toString());
if (id.isEmpty()){
System.out.println("*********in addNewSubFundCalculationMethod: List is empty");
FundSalesCreditCalcMethod fundSalesCreditCalcMethod = new FundSalesCreditCalcMethod();
fundSalesCreditCalcMethod.setSubFundId(dto.getSubFundId());
fundSalesCreditCalcMethod.setEffectiveFromDate(dto.getEffectiveFromDate());
fundSalesCreditCalcMethod.setEffectiveToDate(dto.getEffectiveToDate());
fundSalesCreditCalcMethod.setCreatedBy(dto.getCreatedBy());
fundSalesCreditCalcMethod.setCreatedOn(dto.getCreatedOn());
fundSalesCreditCalcMethod.setLastUpdatedBy(dto.getLastUpdatedBy());
fundSalesCreditCalcMethod.setLastUpdatedOn(dto.getLastUpdatedOn());
fundSalesCreditCalcMethod.setSalesCreditCalcMethodId(1);
fundSalesCreditCalcMethod.setPaymentFrequencyId(1);
Date date = new Date();
fundSalesCreditCalcMethod.setFirstPaymentDate(date);
this.entityManager.persist(fundSalesCreditCalcMethod);
}
}
catch(NoResultException exception){
}
this.entityManager.flush();
return dto;
}
}
帶有子基金表的MApping如下:
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="SubFundId", referencedColumnName = "SubFundId")
private SubFund subFund;
private long salesCreditCalcMethodId;
private long subFundId;
private Date effectiveFromDate;
private Date effectiveToDate;
private long paymentFrequencyId;
private Date firstPaymentDate;
private Date createdOn;
private Date lastUpdatedOn;
private String createdBy;
private String lastUpdatedBy;
Can anyone please help what is the issue.I have been struggling with it from morning.
在您的課程中,您具有兩個映射到同一列SubFundId
,如下所示:
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="SubFundId", referencedColumnName = "SubFundId")
private SubFund subFund;
和
private long subFundId;
因此,hibernate現在對於subFundId
列需要使用哪個字段感到困惑。
為了解決這個問題,您可以刪除long subFundId
字段long subFundId
或者如果兩者都需要,則在private long subFundId
上放置insertable = false, private long subFundId
= false ,如下所示:
@Column(name="SubFundId", insertable = false, updatable = false)
您已聲明對SubFund實體的引用:
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="SubFundId", referencedColumnName = "SubFundId")
private SubFund subFund;
另外,您還聲明了一個映射相同參考的字段
private long subFundId;
選擇要保留的實體,如果需要同時處理實體,則保留第一個實體,如果在所有應用程序中將它們分開處理,則可以省去一些麻煩,而保留第二個實體。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.