java - Not persisted entity with Hibernate -


i have created 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 in cascade 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 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 annoted @service. repository interface implements jparepository<sale, long>.

i'm getting error saying name property of vendor, must not null, null.

thanks!

upd answer, corresponding first version of question entirely removed - in short, suggested flush changes again after entity updated.

current problem in mixing 2 kinds of annotation - first @manytoone annotation belongs jpa specification , second @cascade hibernate specific.

since not hibernate specific in example, solution remove @cascade annotation , add cascadetype.merge @manytoone annotation.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - IIFE: var vs this - is there any difference? -

r - Grow a ffdf data frame on disk gradually -