2011-02-01 88 views

回答

22

當然!從我的經驗來看,它非常有效。下面是一個例子實體:

@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; 
} 
+10

如果您使用的數據,你不必把getter和setter上的每個字段。您可能還想指定EqualsAndHashcode(of = {「id」}) – 2011-12-21 09:20:20

+11

@RoelSpilker是的,但要小心OneToMany和ManyToOne的實體,因爲lombok的ToString會造成無限循環。 – qwertzguy 2013-03-05 13:57:57

8

您還可以使用它與@Data(和它的作品!)

@Entity 
@Data 
public class Customer { 

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

}