Pregunta

es posible? No he visto mucha discusión al respecto.

¿Fue útil?

Solución

Nunca he probado Lombok con Hibernate, pero no veo por qué no debería funcionar. Además, eche un vistazo aquí: http://groups.google.com/group/project-lombok/browse_thread/thread/294bd52d9d8695df/7bc6b0f343831af1?lnk=gst&q=HibERNate#7bc6b0f343831af11

También, Notas de lanzamiento del proyecto Lombok Mencione Hibernate Explícitamente.

Otros consejos

¡Por supuesto! Funciona muy bien desde mi experiencia. Aquí hay una entidad de ejemplo:

@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class PingerEntity {
    // ID
    @Id
    @Getter
    @Setter
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;


    // USER
    @Getter
    @Setter
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private UserEntity user;


    // URL
    @Getter
    @Setter
    @Basic(optional = false)
    private String url;


    /**
     * The number of seconds between checks
     */
    @Getter
    @Setter
    @Basic(optional = false)
    private int frequency; 


    @Getter
    @Setter
    @Basic(optional = false)
    @Enumerated(EnumType.STRING)
    public MonitorType monitorType;
}

Puedes usarlo también con @data (¡y funciona!)

@Entity
@Data
public class Customer {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;
    private String firstName;
    private String lastName;

}

Un ejemplo simple; Library.java:

@Data
@NoArgsConstructor // JPA
@Entity
@Table(name = "libraries")
public class Library {

  @Id
  @GeneratedValue
  private Long id;

  @OneToMany(cascade = CascadeType.ALL)
  @EqualsAndHashCode.Exclude
  // This will be included in the json
  private List<Book> books = new ArrayList<>();

  @JsonIgnore
  public void addBook(Book book) {
    books.add(book);
    book.setLibrary(this);
  }
}

Y Book.java:

@Data
@NoArgsConstructor // JPA
@Entity
@Table(name = "books")
public class Book {

  @Id
  @GeneratedValue
  private Long id;

  @NotBlank
  private String title;

  @ManyToOne
  @JoinColumn(name = "library_id") // Owning side of the relationship
  @EqualsAndHashCode.Exclude
  @JsonIgnore // Avoid infinite loops
  private Library library;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top