First steps and detailed concepts Java Persistence api



Download 0,72 Mb.
Pdf ko'rish
bet13/30
Sana29.10.2022
Hajmi0,72 Mb.
#857994
1   ...   9   10   11   12   13   14   15   16   ...   30
Bog'liq
JPA Mini Book

int
getId() {
return
id;
}
public
void
setId(
int
id) {
this
.id = id;
}
public
String getColor() {
return
color;
}
public
void
setColor(String color) {
this
.color = color;
}
}
About the code above:

The DogFather class is annotated with the @MappedSuperclass annotation. With this annotation 
all DogFather child classes will have its attributes persisted in the database, but DogFather will 
not be mapped to a database table.

A MappedSuperclass can be an abstract or a concrete class.

The Dog class has the ID generator, only Dog is an entity. DogFather is not an entity.
Some recommendations about MappedSuperclass:

A MappedSuperclass cannot be annotated with @Entity\@Table. It is not a class that will be 
26 of 60


JPA Mini Book
www.javacodegeeks.com
persisted. Its attributes/methods will be reflected in its child classes.

It is always a good practice to create it as abstract. A MappedSuperclass will not be used in the 
queries.

Cannot be persisted, it is not an entity.
When do we use it?
If we do not need to use the super class in database queries, it would be a good idea to use a MappedSuperclass. 
In the opposite case it is a good idea to use Entity hierarchy (see the following sections for details).
Mapping Hierarchy: Single Table
With JPA it is possible to find different approaches for persisting class hierarchies. In an Object Orientated language 
like Java it is very easy to find hierarchy between classes that will have their data persisted.
The Single Table strategy will store all hierarchy data into one table. Check the code below:
import
javax.persistence.*;
@Entity
@Table
(name = 
"DOG"
)
@Inheritance
(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn
(name = 
"DOG_CLASS_NAME"
)

Download 0,72 Mb.

Do'stlaringiz bilan baham:
1   ...   9   10   11   12   13   14   15   16   ...   30




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©www.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