Dab tsi yog qhov sib npaug hauv hibernate?
Dab tsi yog qhov sib npaug hauv hibernate?

Video: Dab tsi yog qhov sib npaug hauv hibernate?

Video: Dab tsi yog qhov sib npaug hauv hibernate?
Video: tu txiv tsi pab nkauj tawm tshiab-Cover(niam vamkhwb&paj yeeb& xis xyooj&ntxawm xyooj&niam npawglem) 2024, Kaum ib hlis
Anonim

SEQUENCE yog hom tiam uas pom zoo los ntawm Hibernate cov ntaub ntawv. Cov txiaj ntsig generated yog qhov tshwj xeeb rau ib ntus . Yog koj tsis qhia a ib ntus npe, Hibernate yuav rov siv tib lub hibernate_sequence rau ntau hom.

Khaws qhov no hauv kev xav, @SequenceGenerator yog dab tsi hauv hibernate?

Hom lus piav qhia SequenceGenerator . @Target(value={HMO, METHOD, FIELD}) @Retention(value=RUNTIME) public @interface SequenceGenerator . Txhais lub tshuab hluav taws xob tseem ceeb uas yuav raug hais los ntawm lub npe thaum lub tshuab hluav taws xob tau teev tseg rau GeneratedValue annotation.

Tsis tas li ntawd, cov lus piav qhia twg yog siv rau kev cai database ib ntus hauv hibernate? Ua ntej ntawm tag nrho cov, koj yuav tsum sau ntawv thawj tus cwj pwm tseem ceeb nrog @GeneratedValue lus piav qhia thiab teeb tsa GenerationType. SEQUENCE raws li lub tswv yim. Qhov no qhia Hibernate siv a database sequence los tsim tus nqi tseem ceeb. Yog tias koj tsis muab cov ntaub ntawv ntxiv, Hibernate yuav siv nws lub neej ntawd ib ntus.

Ib yam li ntawd, tib neeg nug, dab tsi yog allocationSize nyob rau hauv ib theem generator?

faibSize - (Yeem) Tus nqi nce ntxiv thaum faib ib ntus cov naj npawb ntawm cov ib ntus . Piv txwv li: lwm daim ntawv thov (xws li siv JDBC dawb) yuav xav ntxig cov kab tshiab hauv qab IDs tau txais los ntawm ib ntus - tab sis tag nrho cov txiaj ntsig no tau siv los ntawm Hibernate!

@GenericGenerator yog dab tsi?

Cov lus piav qhia @GeneratedValue qhia tias tus nqi rau ib kab, uas yuav tsum tau sau nrog @Id yog tsim. @ Cov Generator yog hibernate annotation siv los qhia txog lub tshuab hluav taws xob kev cai, uas tuaj yeem yog chav kawm lossis luv luv rau lub tshuab hluav taws xob muab los ntawm Hibernate.

Pom zoo: