5. You'll need three artifacts to implement a
JPA-compliant program
β’ An entity class
β’ A persistence.xml file
β’ A class through which you will insert, update, or find
an entity
5
7. Order
ΠΡΠΈΠΌΠ΅Ρ ΠΌΠΎΠ΄Π΅Π»ΠΈ
int id
Customer M Customer cust
...
1
int id
String name
int c_rating
Image photo
Set<Order> orders M
Collection<Phone>
phones
Phone
...
int id
Collection<Customer>
N custs
...
7
8. ΠΡΠΈΠΌΠ΅Ρ ΠΎΡΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΡ
CUSTOMER
ID NAME CREDIT PHOTO
@Entity(access=FIELD)
public class Customer {
@Id
int id;
String name;
@Column(name=βCREDITβ)
int c_rating;
@Lob
Image photo;
}
Π£ΠΌΠΎΠ»ΡΠ°Π½ΠΈΡ Π² Π΄Π΅ΠΉΡΡΠ²ΠΈΠΈ:
ΡΠΏΠ΅ΡΠΈΠ°Π»ΡΠ½ΠΎ ΠΎΠΏΠΈΡΡΠ²Π°ΡΡΡΡ ΡΠΎΠ»ΡΠΊΠΎ
ΡΠ°ΡΡ ΠΎΠΆΠ΄Π΅Π½ΠΈΡ Π² ΠΈΠΌΠ΅Π½Π°Ρ . 8
9. ΠΡΠΈΠΌΠ΅Ρ Entity
@Entity
public class Customer implements Serializable {
@Id protected Long id;
protected String name;
@Embedded protected Address address;
protected PreferredStatus status;
@Transient protected int orderCount;
public Customer() {}
public Long getId() {return id;}
protected void setId(Long id) {this.id = id;}
public String getName() {return name;}
public void setName(String name) {this.name = name;}
β¦
}
9