当我提交事务时,会出现此异常。 调用org.hibernate.internal.util.compare.ComparableComparator比较方法,由于两个对象均为null,因此它提供了nullpointer异常。 我不明白为什么要调用ComparableComparator?
存储库类
发生这种情况的原因可能是对循环中的实体进行了一些更新,但没有得到实际的根本原因。
with open('myFile.json', 'r') as f:
for line in f:
tweet = json.loads(line)
print(json.dumps(tweet, indent=4))
异常堆栈跟踪
@Repository
@SuppressWarnings("unchecked")
public class AccountingMigrationDaoImpl implements IAccountingMigrationDao{
@Autowired
private SessionFactory sessionFactory;
@Autowired
private DozerBeanMapper mapper;
@Override
public void compairAndAddWithReservedVoucherList(Integer companyId, List<VoucherTypeMasterDto> listVoucherTypeMasterDtos) {
List<VoucherTypeMaster> listVoucherTypeMasters = null;
List<VoucherTypeMasterDto> rejectedReservedList = new ArrayList<VoucherTypeMasterDto>();
List<VoucherTypeMasterDto> additionalVoucherList = new ArrayList<VoucherTypeMasterDto>();
List<MigrationVoucherTypeMaster> listMigrationVoucherTypeMasters = new ArrayList<MigrationVoucherTypeMaster>();
try {
//---- Get Reserved Voucher List For updating its info against company ------//
listVoucherTypeMasters = sessionFactory.getCurrentSession().getNamedQuery("GET_RESERVED_VOUCHER_LIST").list();
for (VoucherTypeMasterDto voucherTypeMasterDto : listVoucherTypeMasterDtos) {
//---- Find and update reserve voucher list given from tally voucher list -----//
Optional<VoucherTypeMaster> matchingVoucher = listVoucherTypeMasters.stream()
.filter(item -> item.getReserveVoucherName().equalsIgnoreCase(voucherTypeMasterDto.getReserveVoucherName()))
.findFirst();
VoucherTypeMaster voucher = matchingVoucher.orElse(null);
if(voucher != null){
CompanyVoucherTypeMppr comVoucherTypeMppr = mapper.map(voucherTypeMasterDto.getListCompanyVoucherTypeMpprs().get(0), CompanyVoucherTypeMppr.class,"CompanyVoucherTypeMapperMigration");
CompanyVoucherTypeMpprId companyTypeMpprId = new CompanyVoucherTypeMpprId();
companyTypeMpprId.setCompanyId(companyId);
companyTypeMpprId.setVoucherTypeId(voucher.getVoucherTypeId());
comVoucherTypeMppr.setCompanyVoucherTypeMpprId(companyTypeMpprId);
comVoucherTypeMppr.setUseEffectiveDatesForVoucher('Y');
comVoucherTypeMppr.setIsPrinting('N');
comVoucherTypeMppr.setStatus('A');
sessionFactory.getCurrentSession().update(comVoucherTypeMppr);
MigrationVoucherTypeMaster migrationTypeMaster = new MigrationVoucherTypeMaster();
migrationTypeMaster.setCompanyId(companyId);
migrationTypeMaster.setvActualId(voucher.getVoucherTypeId());
migrationTypeMaster.setvTypeName(voucherTypeMasterDto.getVoucherTypeName());
sessionFactory.getCurrentSession().saveOrUpdate(migrationTypeMaster);
listMigrationVoucherTypeMasters.add(migrationTypeMaster);
//---- Ignore extra reserve voucher from tally ----//
}else if(voucherTypeMasterDto.getReserveVoucherName() != null && !voucherTypeMasterDto.getReserveVoucherName().equalsIgnoreCase("")){
rejectedReservedList.add(voucherTypeMasterDto);
//---- Vouchers list except reserve and extra reserve
}else if(voucherTypeMasterDto.getReserveVoucherName().equalsIgnoreCase("")){
additionalVoucherList.add(voucherTypeMasterDto);
}
}
for (VoucherTypeMasterDto voucherTypeMasterDto : additionalVoucherList) {
//------- Checking extra voucher from tally which are not belongs to or childs from rejected voucher list ---//
Optional<VoucherTypeMasterDto> matchingVoucherDto = rejectedReservedList.stream()
.filter(item -> item.getVoucherTypeName().equalsIgnoreCase(voucherTypeMasterDto.getParentVouhcerName()))
.findFirst();
VoucherTypeMasterDto voucherDto = matchingVoucherDto.orElse(null);
if(voucherDto == null){
VoucherTypeMaster voucherTypeMaster = mapper.map(voucherTypeMasterDto, VoucherTypeMaster.class,"VoucherMasterDtoTOVoucherMasterMigration");
Optional<MigrationVoucherTypeMaster> matchingVoucher = listMigrationVoucherTypeMasters.stream()
.filter(item -> item.getvTypeName().equalsIgnoreCase(voucherTypeMasterDto.getParentVouhcerName()))
.findFirst();
MigrationVoucherTypeMaster voucher = matchingVoucher.orElse(null);
voucherTypeMaster.setSuperVoucherTypeId(voucher.getvActualId());
voucherTypeMaster.setCreatedBy(1);
voucherTypeMaster.setCreatedDate(new Date().getTime());
voucherTypeMaster.setIsPrimaryVoucher('N');
voucherTypeMaster.setReserveVoucherName(null);
CompanyVoucherTypeMppr companyVoucherTypeMppr = voucherTypeMaster.getListCompanyVoucherTypeMpprs().get(0);
companyVoucherTypeMppr.setUseEffectiveDatesForVoucher('N');
companyVoucherTypeMppr.setIsPrinting('N');
companyVoucherTypeMppr.setStatus('Y');
CompanyVoucherTypeMpprId companyTypeMpprId = new CompanyVoucherTypeMpprId();
companyTypeMpprId.setCompanyId(companyId);
companyVoucherTypeMppr.setCompanyVoucherTypeMpprId(companyTypeMpprId);
sessionFactory.getCurrentSession().saveOrUpdate(voucherTypeMaster);
companyTypeMpprId.setVoucherTypeId(voucherTypeMaster.getVoucherTypeId());
sessionFactory.getCurrentSession().saveOrUpdate(companyVoucherTypeMppr);
MigrationVoucherTypeMaster migrationTypeMaster = new MigrationVoucherTypeMaster();
migrationTypeMaster.setCompanyId(companyId);
migrationTypeMaster.setvActualId(voucherTypeMaster.getVoucherTypeId());
migrationTypeMaster.setvTypeName(voucherTypeMaster.getVoucherTypeName());
sessionFactory.getCurrentSession().saveOrUpdate(migrationTypeMaster);
listMigrationVoucherTypeMasters.add(migrationTypeMaster);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}