First steps and detailed concepts Java Persistence api


import javax.persistence.Entity; import



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

import
javax.persistence.Entity;
import
javax.persistence.Id;
@Entity
public
class
Car {
8 of 60


JPA Mini Book
www.javacodegeeks.com
public
Car(){
}
public
Car(
int
id){
this
.id = id;
}
// Just to show that there is no need to have get/set when we talk about JPA Id
@Id
private
int
id;
private
String name;
public
String getName() {
return
name;
}
public
void
setName(String name) {
this
.name = name;
}
}
About the code above:

The class has the annotation @Entity above its name

There is an attribute considered the id of the class that is annotated with @Id. 
Every entity must 
have an id
. Usually this field is a sequential integer field, but it can be a String or other allowed 
values

Notice that there is no get/set for the id attribute. For JPA is concidered that an entity's id is 
immutable, so there is no need to edit the id value.

The presence of a public constructor without arguments is mandatory. Other constructors may 
be added
As shown in the code snippet above we only used two annotations, one to define an entity and another to declare 
the "id" field; by default JPA will look for a table named CAR in the database with columns named ID and NAME. By 
default JPA will use the class name and the class attribute names to find the tables and its structures.
According to the book “Pro JPA 2” we can define the JPA annotations in two ways: Logical annotations and Physical 
annotations. The physical annotations will map the configuration of the database into the class. The logical 
annotations will define the application modeling. Check the code below:

Download 0,72 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   ...   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