29 Mart 2018 Perşembe

Hibernate @GenericGenerator Anotasyonu

Giriş
Şu satırı dahil ederiz.
import org.hibernate.annotations.GenericGenerator;
Şu generator'leri sağlar.
static {
    GENERATORS.put("uuid", UUIDHexGenerator.class);     // "deprecated" for new use
    GENERATORS.put("hilo", TableHiLoGenerator.class);   // removed in Hibernate 5
    GENERATORS.put("assigned", Assigned.class);
    GENERATORS.put("identity", IdentityGenerator.class);
    GENERATORS.put("select", SelectGenerator.class);
    GENERATORS.put("sequence", SequenceGenerator.class);
    GENERATORS.put("seqhilo", SequenceHiLoGenerator.class);
    GENERATORS.put("increment", IncrementGenerator.class);
    GENERATORS.put("foreign", ForeignGenerator.class);
    GENERATORS.put("guid", GUIDGenerator.class);
    GENERATORS.put("uuid.hex", UUIDHexGenerator.class); // uuid.hex is deprecated
    GENERATORS.put("sequence-identity", SequenceIdentityGenerator.class);
}
Şu generator'leri sağlar.
register("uuid2", UUIDGenerator.class);
register("enhanced-sequence", SequenceStyleGenerator.class);
register("enhanced-table", TableGenerator.class);
Örnek
Şöyle yaparız.
@Id
@GeneratedValue(generator="increment")
@GenericGenerator(name="increment", strategy = "increment") 
Long id;
Örnek - sequence
Şöyle yaparız.
@Id
@GenericGenerator(name="honeySequence", strategy = "sequence", 
  parameters = { 
    @Parameter(name="sequence", value="HONEY_SEQ") } 
  )
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="honeySequence")
private int Id;
Örnek - uuid2
Şöyle yaparız.
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID", strategy = "uuid2")
@Column(name = "id",nullable = false, updatable=false)
@Type(type="uuid-char")
private UUID id;

Hiç yorum yok:

Yorum Gönder