I have created this code:
Sale sale = new Sale(); saleService.create(sale); Vendor vendor = new Vendor("name"); Sale updatedSale = saleService.findById(sale.getId()); updatedSale.setVendor(vendor); try { saleService.update(updatedSale); } catch (EntityNotFoundException ex) { System.err.println(""); } Also, sale is in cascade with vendor:
@ManyToOne(cascade={CascadeType.PERSIST,CascadeType.REFRESH}, targetEntity = Vendor.class) @Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.PERSIST }) private Vendor vendor; The saleService has this code:
@Transactional public Sale create(Sale entity) { Sale created = entity; saleRepository.saveAndFlush(created); return created; } @Transactional(rollbackFor = EntityNotFoundException.class) public Calibration update(Calibration entity) throws EntityNotFoundException { if (!calibrationRepository.exists(entity.getId())) { throw new EntityNotFoundException(); } return calibrationRepository.saveAndFlush(entity); } It's also annoted as @Service. The repository is an Interface that implements JpaRepository<Sale, Long>.
I'm getting an Error saying that the name property of Vendor, that must not be null, is null.
Thanks!
Sale.