java - Hibernate, OneToMany relationship and unwanted update -


i'm developing spring-hibernate java application following entities (the unnecessary lines of code have been removed make reading code easier):

@entity public class useraccount extends identityentity {      ...      @onetomany(cascade = cascadetype.all, fetch = fetchtype.lazy)     @joincolumn(name = "user_account_id", nullable = false)     protected list<userdevice> devices = new arraylist<userdevice>();      ...      } 

and

@entity public class userdevice extends identityentity {      ...      @manytoone(fetch = fetchtype.lazy)     @joincolumn(name = "user_account_id", nullable = false, insertable=false, updatable=false)     protected useraccount useraccount;      ...  } 

the generated tables are:

user , device tables

i wrote junit test (the unnecessary lines of code have been removed make reading code easier) :

@test @transactional public void testmainscenario() {     useraccount user=useraccountcreate("dummy");     useraccountsaveorupdate(user);      userdevice device=userdevicerepository.createentity();      device.setuseraccount(user);     user.getdevices().add(device);      userdevicerepository.saveorupdate(device);      list<userdevice> lista = userdevicerepository.list();     logger.info(lista.tostring()); } 

when run test, following query generated , executed:

info  p6spy - sql: values next value hibernate_sequence info  p6spy - sql: insert user_account (creation_time, update_time, uid, email, email_verified, enabled, name, password, username, id) values ('20-apr-16', '20-apr-16', '8387a3ae-7023-4a40-a4c6-242851d19b12', 'dummy@dummy.org', 0, 0, null, 'e4b20227-a946-421e-8e33-c90346c60d2e', 'dummy', 1) info  p6spy - sql: values next value hibernate_sequence info  p6spy - sql: insert user_device (creation_time, update_time, uid, access_token, description, name, user_account_id, id) values ('20-apr-16', '20-apr-16', 'c549cd4c-32dc-4ace-8b63-6f7c7a8fa454', null, null, null, 1, 2) info  p6spy - sql: update user_device set user_account_id=1 id=2 

the question is: how can avoid last update user_device table after device insert sql? it's not needed.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -