Am I supposed to call EntityManager.clear() often to avoid memory leaks?

后端 未结 3 1115
滥情空心
滥情空心 2021-01-12 03:39

I\'m new to JPA/OpenJPA and I noticed that if I don\'t call EntityManager.clear() after i persist entities I get an OutOfMemoryError (I keep adding

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-12 04:29

    It sounds like there is something wrong somewhere, in your design. Usually, the entity gets detached once it is outside the scope of entity manager. And thats one of the reason you can't lazy load relations, outside the scope.

    As far as my experience is concerned, I seldom used em.clear(), if ever. I used Hibernate implementation, and Toplink Essentials. No experience with OpenJPA, yet.

提交回复
热议问题