Shared publicly  - 
 
Just because you're using Hibernate, doesn't mean you have to use it for everything. A point I've been making for about ten years now.
21
8
Nicolas Phung's profile photoCarlos Perez Chavez's profile photoHumberto Anjos's profile photoEdgardo Damian Alvarez's profile photo
6 comments
 
Wow. Do I understand correct that all this bonanza of maven XML, boilerplate code and annotations - all this is needed to just generate nice little select statement with that funny DSL based on builder pattern? 
 
+Igor Shabalov Dunno, I'm not a Maven user, at least not when I can possibly avoid it. I assume that Maven is more to blame for all this XML than Hibernate or JOQL.
 
+Igor Shabalov It's for maven, and usually it's a write-once forget-about approach, plus he is generating everything, all the code you see except for the test in the end is all generated and keep itself updated as part of the build process. Since is maven, one could just grab the pom.xml and the test file and compile in his own machine without having to manually download and setup all the tools involved with all the right versions. It gets really good once you have lots of ppl plus lots of libraries to make it all available to everyone
 
+Igor Shabalov : +Vlad Mihalcea tries to write only one domain model (JPA-annotated) and then derive all other artefacts through various code generators. Yes, it's a write-once forget-about approach, which helps him to be very efficient afterwards
 
After suffering undersleep, stress and tears, I realized that the best approach is to write SQL to get Ids, and JPQL (usually with the NEW operator to avoid the infamous N+1 problem) to get the objects.

If only native SQL supported named parameters... And why can't I use nested NEWs inside JPQL? Hell, why the named parameter restriction inside a NEW? Is it really that hard? JPQL needs a massive revamp. Seriously.
 
If you want to avoid N+1 for whatever reason, just use join fetch. Nested new as in more than one entity in the same native query? you need to use a result set mapping. My gripes with the current approach is just that I'm stuck to old versions of hibernate (JEE 5) and I get N+1 from onetone mappings, but I don't blame the spec for my limitations
Add a comment...