![](/img/trans.png)
[英]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.