tag:blogger.com,1999:blog-2526628884837213668.post8807185365512646038..comments2024-03-27T00:14:35.505-07:00Comments on Adapting and Learning: JPA Pitfalls / MistakesLorenzo Deehttp://www.blogger.com/profile/00551506284562303520noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-2526628884837213668.post-76872207017878562192021-03-12T05:17:46.126-08:002021-03-12T05:17:46.126-08:00Something I haven't seen mentioned anywhere bu...Something I haven't seen mentioned anywhere but I think it's also a good idea, is deprecating the no-args constructors when there are better options. So I'd say, apart from making the no-args constructor protected and providing a public constructor with the required fields (so at least those which are non-nullable), one should add the @Deprecated annotation, and document which alternative to use with @deprecated in the javadoc. A nice thing about this is that the IDE usually warns you about deprecated things, so any developer unaware of it will be warned. In java 9 or above, one can further use the forRemoval = false of the @Deprecated annotation, to make it explicit that it won't be removed (because JPA/Spring/whatever requires de no-args constructor), but it should still be avoided.Cristian.-https://www.blogger.com/profile/08817845436106531111noreply@blogger.comtag:blogger.com,1999:blog-2526628884837213668.post-6944818479288036072016-01-13T18:42:00.715-08:002016-01-13T18:42:00.715-08:00Yes, for some JPA providers like Hibernate, the JP...Yes, for some JPA providers like Hibernate, the JPA-required no-arg constructor can have package-private access. But this will make your JPA code non-portable.<br /><br />Thanks for asking Redan.Lorenzo Deehttps://www.blogger.com/profile/00551506284562303520noreply@blogger.comtag:blogger.com,1999:blog-2526628884837213668.post-24863972744279391002016-01-11T23:01:59.785-08:002016-01-11T23:01:59.785-08:00Can the JPA-required no-arg constructor have packa...Can the JPA-required no-arg constructor have package-private access?Anonymoushttps://www.blogger.com/profile/01147752821191648444noreply@blogger.com