martes, 25 de diciembre de 2012

HIbernate - Annotations

Hibernate annotations

@Entity - To persist the class
@Basic  - Customized the persistance as lazy mode or aspects
@Transient  - Don't persist
@Temporal  - To persist dates  Ex. @Temporal(TemporalType.TIMESTAMP)
@Table  - To use a different name from table Ex. @Table(name = "HOGWASH")
@Column  - To map a column with different name @Column(name = "commentText")
@Id  - Define attribute as primary key

@GeneratedValue  - Use with @Id to create an identifier, by default AUTO. Ex @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="COMMENT_ID_SEQ") to specify a different behavior


@OneToMany  - To establish the relation. Ex 
@OneToMany(orphanRemoval = true, cascade = { javax.persistence.CascadeType.ALL }) 
orphanRemoval - Delete any dereferenced
javax.persistence.CascadeType  - The eentity will be affected in any save/update

@Cache  - First try to find an instance in the cache, helpful for improve performance  Ex. @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
CacheConcurrencyStrategy.NONSTRICT_READ_WRITE -  In case of update the cache will be invalid

@Inheritance  - Ex. @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
Types : Implicit polymorphism, Table-per-hierarchy, Table-per-subclass, Table-per-concrete-class 

@ManyToMany  - Ex. @ManyToMany(mappedBy = "artEntities")
mappedBy -  Define which table owns the relationship






No hay comentarios:

Publicar un comentario