Hibernate / JPA - EntityNotFoundException: Unable to find with id -


i have scenario 2 entities have @manytoone relation.the app uses both spring data jpa , hibernate. trying save child entity through spring data jpa repo's save() method , other through hibernate's getsession().save(). ending entity not found exception. after first save, not inserting record in db because of later save failing. looking solution make work!

samplecode:

entitya  = new entitya(); entityadao.save(); //not inserting record  entityb b = new entityb(); b.setentitya(a); b.save(); //throwing entitya not found exception. 

test class:

@runwith(springjunit4classrunner.class) @contextconfiguration(locations = { "classpath:test-application-context-dao.xml" }) @transactional(propagation= propagation.requires_new) public class entitytest{      @autowired     private entityadao entityadao;      private entitybdao entitybdao;       @autowired     private sessionfactory sessionfactory;      @postconstruct     public void orderdaotest()     {         subject = new entitybdaoimpl (sessionfactory);         system.setproperty("server_type", "junit"); // need     }      @test     public void testlistbyentityb()     {          entitya  = new entitya();         a.setid("123");         entityadao.save(); //not inserting record          entityb b = new entityb();         b.setentitya(a);         b.save(); //throwing entitya not found exception id "123".           list<entityb> blist = entitybdao.listbyid(a.getid());      }   } 

thanks, preethi


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -