Can Lombok be used with Hibernate ?

1,837 views
Skip to first unread message

Suresh Anbarasan

unread,
Dec 2, 2013, 11:43:02 PM12/2/13
to project...@googlegroups.com
In many projects we use retrospection (through java reflection) and hibernate (which requires the getter method for lazy initialization). Can we use Lombok for those projects ?

Joseph Ottinger

unread,
Dec 3, 2013, 6:07:29 AM12/3/13
to project...@googlegroups.com

Yes.

On Dec 3, 2013 3:34 AM, "Suresh Anbarasan" <antha...@gmail.com> wrote:
In many projects we use retrospection (through java reflection) and hibernate (which requires the getter method for lazy initialization). Can we use Lombok for those projects ?

--
You received this message because you are subscribed to the Google Groups "Project Lombok" group.
To unsubscribe from this group and stop receiving emails from it, send an email to project-lombo...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Martin Grajcar

unread,
Dec 3, 2013, 10:00:52 PM12/3/13
to project...@googlegroups.com
Sure, all these things come after Lombok did its job.

Reinier Zwitserloot

unread,
Dec 4, 2013, 1:19:20 AM12/4/13
to project-lombok
Lombok's received a JPA update a long time ago to make sure all this works well. A few caveats:

* You might want to use @EqualsAndHashCode(of="unid"). Opinions differ on how to model equals and hashCode methods for JPA objects. You should either exclude the primary key and use all other fields, or go only by primary key and never look at the rest. Lombok doesn't know you're using this class as a JPA model, so you need to specify this.

* By default, if a getX() method exists, whether lombok generated it or not, those will be used where relevant (equals, hashCode, toString, etc). That does mean that calling .toString() on a 'deep' structure will cause JPA to go haywire and query tons of objects. In practice you actually usually want this (because most db structures aren't that deep), but you can suppress it using doNotUseGetters=true.

retrospection is no issue at all; lombok is a compile-time only dependency. After your project has been compiled, it looks indistinguishable from code written out without the benefit of lombok to get rid of some boilerplate. getters and the like that lombok generated show up, equal in all ways to a hand-written one.

 --Reinier Zwitserloot

Fabrizio Giudici

unread,
Dec 4, 2013, 4:03:34 AM12/4/13
to project-lombok, Reinier Zwitserloot
I can confirm a quite large project I'm consulting for has been designed
with Lombok and JPA/EclipseLink (which implementation details are a bit
different than Hibernate; I'm saying just for the sake of possible other
JPA users).


--
Fabrizio Giudici - Java Architect @ Tidalwave s.a.s.
"We make Java work. Everywhere."
http://tidalwave.it/fabrizio/blog - fabrizio...@tidalwave.it
Reply all
Reply to author
Forward
0 new messages