Lombok 0.10.1 @Data breaks all JPA @Entity objects?

2,227 views
Skip to first unread message

Jacek Furmankiewicz

unread,
Oct 18, 2011, 11:15:31 AM10/18/11
to project...@googlegroups.com
I just upgrade our project from 0.9 to 0.10.1 and all our JPA/Hibernate code is failing.

it seems @Data does not generate a no-args constructor any more and thus breaks all @Entity objects.
We'd have to go through hundreds of JPA entities and add @NoArgsConstructor to all of them!

Is this a bug? Design? Can it be changed so that on @Entity objects @Data is smart enough to leave the no-args constructor?

Jacek

Philipp Eichhorn

unread,
Oct 18, 2011, 2:00:59 PM10/18/11
to Project Lombok
Hi Jacek,

as far as I can tell @Data works perfectly fine.
Please note that @Data is not a shorthand for @NoArgsConstructor,
@Getter, @Setter, @EqualsAndHashCode and @ToString, but rather
@RequiredArgsConstructor, ..... and @ToString.
It would be nice, if you could add a small code example.

-- Philipp

Jason Hamm

unread,
Oct 18, 2011, 2:45:40 PM10/18/11
to project...@googlegroups.com
 
Here is the whole class.
 

import lombok.Data;

public @Data class Mountain {

private final String name;

private final double latitude, longitude;

private String country;

}

I am going to try it again at the house later.  I will email you in the morn and let you know if i have any luck.  thanks for the emails.



--
You received this message because you are subscribed to the Google
Groups group for http://projectlombok.org/

To post to this group, send email to project...@googlegroups.com
To unsubscribe from this group, send email to
project-lombo...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/project-lombok?hl=en

AndreBogus

unread,
Oct 18, 2011, 7:18:10 PM10/18/11
to Project Lombok
@Jacek: That is not an entity class. Entity classes must not have
final fields. As per the J2EE tutorial: "The class must not be
declared final. No methods or persistent instance variables must be
declared final."

Remove the "final" from your instance variables and it will work.

Jason Hamm

unread,
Oct 19, 2011, 5:22:48 AM10/19/11
to project...@googlegroups.com
It works perfect now.  Thanks.  How come in the video on the website, they dont have to use non final variables?  Anyway, I will definitely start using lombok.

Makoto Hashimoto

unread,
Nov 2, 2011, 4:11:18 PM11/2/11
to Project Lombok
Hi,

I have the same problem, but in my case is a little diferent. I didn't
use final in my attributes I use the annotation @NotNull.
There's

There's something that I can do? Or the unique solution is stop use
the @Data and use just @Getter and @Setter?

Follow my code.

package br.com.ligdiagnosticos.scl.model.exame;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

import lombok.Data;
import br.com.ligdiagnosticos.scl.model.apoio.Convenio;
import br.com.ligdiagnosticos.scl.model.apoio.Medico;
import br.com.ligdiagnosticos.scl.model.apoio.Procedencia;
import br.com.ligdiagnosticos.scl.model.apoio.Usuario;
import br.com.ligdiagnosticos.scl.model.common.GenericEntity;

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract @Data class Exame extends GenericEntity {

private static final long serialVersionUID = -7215894532261917873L;

@NotNull
@ManyToOne
private Amostra amostra;

@Temporal(TemporalType.DATE)
private Date dataLiberacao;

@ManyToOne
private Medico medico;

@ManyToOne
private Convenio convenio;

@ManyToOne
private Procedencia procedencia;

@ManyToOne
@NotNull
private Usuario responsavel;

@ManyToOne
@NotNull
private Usuario tecnicoLiberacao;

private String obs;

public abstract String getNomeExame();
}

Best regards,
Makoto Hashimoto

On Oct 19, 7:22 am, Jason Hamm <jhamm.busin...@gmail.com> wrote:
> It works perfect now.  Thanks.  How come in the video on the website, they
> dont have to use non final variables?  Anyway, I will definitely start using
> lombok.
>
> On Tue, Oct 18, 2011 at 7:18 PM, AndreBogus <bogusan...@googlemail.com>wrote:
>
>
>
>
>
>
>
> > @Jacek: That is not an entity class. Entity classes must not have
> > final fields. As per the J2EE tutorial: "The class must not be
> > declared final. No methods or persistent instance variables must be
> > declared final."
>
> > Remove the "final" from your instance variables and it will work.
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups group forhttp://projectlombok.org/

Reinier Zwitserloot

unread,
Nov 2, 2011, 7:57:28 PM11/2/11
to project...@googlegroups.com
Switch to 0.10.2, problem solved ;)

Makoto Hashimoto

unread,
Nov 3, 2011, 7:30:38 AM11/3/11
to project...@googlegroups.com
Thanks, it work now :)

Best regards,
Makoto Hashimoto



On Wed, Nov 2, 2011 at 21:57, Reinier Zwitserloot <rein...@gmail.com> wrote:
Switch to 0.10.2, problem solved ;)

--
You received this message because you are subscribed to the Google
Groups group for http://projectlombok.org/
Reply all
Reply to author
Forward
0 new messages