실제 소스


@Data
@SuppressWarnings({ "PMD.UnusedPrivateField", "PMD.SingularField" })
@Entity
@Table(name = "products")
@EqualsAndHashCode(of = { "productId" })
@EntityListeners({ CreatedAtListener.class, ModifiedAtListener.class })
public class Product implements Creatable, Modifiable, Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "productId")
    private Long productId;

    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "productId", updatable = false)
    private List<Item> items;

    @Column(name = "categoryId", nullable = false)
    private Long categoryId;

    @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
    @JoinColumn(name = "productId", nullable = false, updatable = false)
    @MapKeyColumn(name = "locale", updatable = false)
    @MapKeyEnumerated(EnumType.STRING)
    private Map<VitaminLocale, ProductLocale> productLocales = Maps.newHashMap();

    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "productId", updatable = false)
    @OrderBy("exposeOrder ASC")
    @Where(clause = "deleted = 0")
    private List<ProductContent> productContents;

    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "productId", updatable = false)
    @OrderBy("weight ASC")
    @Where(clause = "deleted = 0")
    private List<ProductAttributeWeight> productAttributeWeights;

    @Enumerated(EnumType.STRING)
    @Column(name = "divisionType", length = 16, nullable = false)
    private DivisionType divisionType;

    @Column(name = "valid", nullable = false, columnDefinition = "TINYINT")
    private boolean valid = true;

    @Column(name = "bundled", nullable = false)
    private Boolean bundled = false;

    @Enumerated(EnumType.STRING)
    @Column(name = "baseUnit", nullable = false)
    private Unit baseUnit;

    @Column(name = "unitPriceBasis", nullable = false)
    private Integer unitPriceBasis;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "createdAt", nullable = false)
    private Date createdAt;    //NOSONAR

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "modifiedAt", nullable = false)
    private Date modifiedAt;    //NOSONAR

    @Column(name = "regId", length = 40, updatable = false)
    private String regId;

    @Column(name = "updId", length = 40)
    private String updId;

    @Column(name = "expose", nullable = true, columnDefinition = "TINYINT")
    private Boolean expose = Boolean.TRUE;

    @Enumerated(EnumType.STRING)
    @Column(name = "cleansing", nullable = true)
    private CleanType cleansing = CleanType.INITIAL;

    @Transient
    private List<Category> categories;     //NOSONAR

    @Transient
    private List<ProductAttributeType> productAttributeTypes;        //NOSONAR

    @Transient
    private List<ProductProperty> productProperties;         //NOSONAR
    ...
}

Annotations

Annotation Description
@SuppressWarnings https://goo.gl/RLB75u
@Transient 어떤 속성을 테이블의 필드로 만들고 싶지 않을 때

Entity listeners and Callback methods

https://docs.jboss.org/hibernate/entitymanager/3.6/reference/en/html/listeners.html

Type Description
@PrePersist Executed before the entity manager persist operation is actually executed or cascaded. This call is synchronous with the persist operation.
@PreRemove Executed before the entity manager remove operation is actually executed or cascaded. This call is synchronous with the remove operation.
@PostPersist Executed after the entity manager persist operation is actually executed or cascaded. This call is invoked after the database INSERT is executed.
@PostRemove Executed after the entity manager remove operation is actually executed or cascaded. This call is synchronous with the remove operation.
@PreUpdate Executed before the database UPDATE operation.
@PostUpdate Executed after the database UPDATE operation.
@PostLoad Executed after an entity has been loaded into the current persistence context or an entity has been refreshed.

results matching ""

    No results matching ""