How could intellij changed Hibernate lazyload rules with breakpoint?
I figured out a small breakpoint on a specific line can change hibernate rules... I wonder how it could happen without my permission!
(You can reproduce this issue on sample repo)
# Given
There are three entities: Post, Comment, User.
Post : Comment = 1 : N
Comment : User = N : 1
So each comment is connected to 1 post and 1 user. A user or a post can have multiple comments.
I set bidirectional relation with JPA/Hibernate annotations and set fetch type as LAZY load on every relation (@OneToMay, @ManyToOne)
Lastly, I created sample entities: post A, user B, and 1 comment, which is connected to post A and user B.
# When
query post A, and try to read A's comments. the method looks like this:
# Then (Normal Behavior)
When I run my SpringBoot app without any debug setup, these are the printed console logs: (I edited a little for readability)
START---------------------------------Hibernate: select p.id, p.name from post pNAME________________________________________post_AHibernate: select c.post_id, c.id, c.id, c.post_id, c.text, c.user_id from comment c where c.post_id=?COMMENTS________________________________________[com.example.test2.test.Comment@410f89]
START---------------------------------Hibernate: select p.id, p.name from post pHibernate: select c.post_id, c.id, c.id, c.post_id, c.text, c.user_id from comment c where c.post_id=?NAME________________________________________post_ACOMMENTS________________________________________[com.example.test2.test.Comment@410f89]
Does anyone know why this happen?
# More weird thing
This symptom is not consistent, because when I tried with Comment instead of Post, everything works as expected.
I think Collection types have something to do with this case... but not sure.
请先登录再写评论。
Hi Roeniss2 It looks like the IDE executes the line below System.out.println("NAME" + p.name); which leads to lazy comments initialization.
Please try to mute renderers and restart the debugger.
Egor Klepikov, Thank you. `mute renderer` wat the key that I needed. Problem solved.