First steps and detailed concepts Java Persistence api


import javax.persistence.Entity; import



Download 0,72 Mb.
Pdf ko'rish
bet7/30
Sana29.10.2022
Hajmi0,72 Mb.
#857994
1   2   3   4   5   6   7   8   9   10   ...   30
Bog'liq
JPA Mini Book

import
javax.persistence.Entity;
import
javax.persistence.GeneratedValue;
import
javax.persistence.GenerationType;
import
javax.persistence.Id;
@Entity
public
class
Person {
@Id
@GeneratedValue
(strategy = GenerationType.IDENTITY)
private
int
id;
private
String name;
public
String getName() {
return
name;
}
public
void
setName(String name) {
this
.name = name;
}
}
The database controls the ID generation, JPA does not act on the id at all. Thus in order to retrieve the id from the 
databse an entity needs to be persisted first, and after the transaction commits, a query is executed so as to 
retrieve the generated id for the specific entity. This procedure leads to a small performance degradation, but not 
something troublesome.
The aforementioned id generation approach does not allow allocating ids in memory. We will examine what this ids 
allocation means in the following chapters.
11 of 60


JPA Mini Book
www.javacodegeeks.com
Sequence
The Sequence approach can be configured like below:
import
javax.persistence.Entity;
import
javax.persistence.GeneratedValue;
import
javax.persistence.GenerationType;
import
javax.persistence.Id;
import
javax.persistence.SequenceGenerator;
@Entity
@SequenceGenerator
(name = Car.CAR_SEQUENCE_NAME, sequenceName = Car.CAR_SEQUENCE_NAME, initialValue = 
10

allocationSize = 
53
)
public
class
Car {
public
static
final
String CAR_SEQUENCE_NAME = 
"CAR_SEQUENCE_ID"
;
@Id
@GeneratedValue
(strategy = GenerationType.SEQUENCE, generator = CAR_SEQUENCE_NAME)

Download 0,72 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   10   ...   30




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish