java - Spring Data JPA: Why findOne(id) executing delete query internally? -


i have 1 application using @manytomany annotation link 2 different entities 1 parent entity. not sure if have implemented properly. when execute .findone() on parent entity's repository find it, @ first fetch data along executing delete queries internally delete record mapping table (a table jpa creates after adding @manytomany annotation.). following generated sql queries , code snippet:

java class

@entity @table(name = "inventory") public class inventory {      @id     long id;      // many other properties      @manytomany(fetch=fetchtype.lazy)     private list<stream> streams;      @manytomany(fetch=fetchtype.lazy)     private list<subject> subjects; }   

there no other annotation i've put in stream , subject entity class link inventory class.

when run app, create following tables:

inventory
stream
subject
inventory_stream
inventory_subject

(inventory_stream , inventory_subject, 2 tables created automatically, don't know how curious know , finding out, no luck far, please give insight in context well).

service class

@transactional public class inventoryservice {    public inventory getinventorybyid(integer id) {       inventory inv = invrepository.findone(id);       if(inv == null) {             throw new notfoundexception("entity not found id: "+id);       }       return inv;   } }  

console log in eclipse

hibernate: select streams0_.inventory_id inventor1_1_0_, streams0_.streams_id streams_2_2_0_, stream1_.id id1_6_1_, stream1_.stream stream2_6_1_ inventory_stream streams0_ inner join stream stream1_ on streams0_.streams_id=stream1_.id streams0_.inventory_id=? hibernate: delete inventory_stream inventory_id=? hibernate: select subjects0_.inventory_id inventor1_1_0_, subjects0_.subjects_id subjects2_3_0_, subject1_.id id1_7_1_, subject1_.subjectname subjectn2_7_1_ inventory_subject subjects0_ inner join subject subject1_ on subjects0_.subjects_id=subject1_.id subjects0_.inventory_id=? hibernate: delete inventory_subject inventory_id=?   

update

removed following properties applicationcontext.xml (entitymanagerfactory):

<property name="jpaproperties">     <props>         <prop key="hibernate.enable_lazy_load_no_trans">true</prop>     </props> </property>   

and changed fetchtype.lazy fetchtype.eager, resolved issues, created issue, returning duplicate data in list<stream> , list<subject> when return single bean of inventory. don't think enable_lazy_load_no_trans root cause of initial issue.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -