Use of lombok in entity definition

Hi,

#www.data-ware.it

we often use lombok in our rest projects
#https://projectlombok.org/
to let code be more easy to read.

why dont you integrate lombok ?
you could remove al get and set methods in the entity declaration.

I think you already know the lombok library.
So I’m courious to know why you dont use it
regards
Stefano

Hello,
would this work? I haven’t tried it myself.

Kind regards,
Mladen

Yes it works!
very well.
I use it since 6 years more or less …

example:

// www.data-ware.it

package it.dataware.test.model.entities;

import lombok.Data;
import org.checkerframework.checker.units.qual.Length;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

import javax.persistence.*;
import java.io.Serializable;

@Data
@Entity
@Table(name = “Countries”)
public class Country implements Serializable {
@Id
@Column(name = “CodeISO”, insertable = false, updatable = false, length = 2)
@Generated(GenerationTime.INSERT)
private String id;

@Column(name = "Name", length = 50)
private String nome;

}

get & set of attributes are generate automatically.

Please never use @Data for Jmix entities. It will prevent correct generation of equals/hashCode methods by entity enhancement.

See also Lombok and JPA: What Could Go Wrong? - DZone

Regards,
Konstantin

2 Likes

ok. I dont use it in JMix.
the question is why Jmix (developers) cannot use Lombok ?

In fact you can. Just at your own risk, we don’t test this.

1 Like

Lombok is often became the source of development workflow breaks and unexpected behaviour in code. This makes developers in love with IDE productivity features like code generartion with Alt+Insert menu:)
image

1 Like