Commit 907e7fbd by Patryk Czarnik

Poprawki, aby się kompilowało

parent 564ef422
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"> xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
<persistence-unit name="PC27-SklepHibernate"> <persistence-unit name="sklep">
<class>sklep.model.Customer</class> <class>sklep.model.Customer</class>
<class>sklep.model.OrderProduct</class> <class>sklep.model.OrderProduct</class>
<class>sklep.model.OrderProductPK</class> <class>sklep.model.OrderProductPK</class>
......
...@@ -2,13 +2,9 @@ package sklep.model; ...@@ -2,13 +2,9 @@ package sklep.model;
import java.io.Serializable; import java.io.Serializable;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.Pattern;
import java.util.List; import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnore;
/** /**
* The persistent class for the customers database table. * The persistent class for the customers database table.
...@@ -22,7 +18,6 @@ public class Customer implements Serializable { ...@@ -22,7 +18,6 @@ public class Customer implements Serializable {
@Id @Id
@Column(name="customer_email", updatable=false) @Column(name="customer_email", updatable=false)
@Email
private String customerEmail; private String customerEmail;
private String address; private String address;
...@@ -36,12 +31,10 @@ public class Customer implements Serializable { ...@@ -36,12 +31,10 @@ public class Customer implements Serializable {
private String phoneNumber; private String phoneNumber;
@Column(name="postal_code") @Column(name="postal_code")
@Pattern(regexp="\\d{2}-\\d{3}")
private String postalCode; private String postalCode;
//bi-directional many-to-one association to Order //bi-directional many-to-one association to Order
@OneToMany(mappedBy="customer") @OneToMany(mappedBy="customer")
@JsonIgnore
private List<Order> orders; private List<Order> orders;
public Customer() { public Customer() {
......
...@@ -2,14 +2,9 @@ package sklep.model; ...@@ -2,14 +2,9 @@ package sklep.model;
import java.io.Serializable; import java.io.Serializable;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.validation.constraints.DecimalMax;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.Min;
import java.math.BigDecimal; import java.math.BigDecimal;
import com.fasterxml.jackson.annotation.JsonIgnore;
/** /**
* The persistent class for the order_products database table. * The persistent class for the order_products database table.
...@@ -25,21 +20,16 @@ public class OrderProduct implements Serializable { ...@@ -25,21 +20,16 @@ public class OrderProduct implements Serializable {
private OrderProductPK id; private OrderProductPK id;
@Column(name="actual_price") @Column(name="actual_price")
@DecimalMin("0.01")
private BigDecimal actualPrice; private BigDecimal actualPrice;
@Column(name="actual_vat") @Column(name="actual_vat")
@DecimalMin("0.00")
@DecimalMax("0.99")
private BigDecimal actualVat; private BigDecimal actualVat;
@Min(1)
private Integer quantity; private Integer quantity;
//bi-directional many-to-one association to Order //bi-directional many-to-one association to Order
@ManyToOne @ManyToOne
@JoinColumn(name="order_id", insertable=false, updatable=false) @JoinColumn(name="order_id", insertable=false, updatable=false)
@JsonIgnore
private Order order; private Order order;
//uni-directional many-to-one association to Product //uni-directional many-to-one association to Product
......
...@@ -2,7 +2,6 @@ package sklep.model; ...@@ -2,7 +2,6 @@ package sklep.model;
import java.io.Serializable; import java.io.Serializable;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.validation.constraints.*;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -24,16 +23,11 @@ public class Product implements Serializable { ...@@ -24,16 +23,11 @@ public class Product implements Serializable {
private String description; private String description;
@NotNull
@DecimalMin("0.01")
private BigDecimal price; private BigDecimal price;
@Column(name="product_name") @Column(name="product_name")
@NotBlank
private String productName; private String productName;
@DecimalMin("0.00")
@DecimalMax("0.99")
private BigDecimal vat; private BigDecimal vat;
public Product() { public Product() {
......
package sklep.przyklady_hibernate;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;
import sklep.model.Product;
public class OdczytajJedenProdukt {
public static void main(String[] args) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("sklep");
EntityManager em = emf.createEntityManager();
System.out.println("Mam EntityManagera: " + em);
Product product = em.find(Product.class, 2);
System.out.println("Mam obiekt: " + product);
System.out.println(product.getProductName() + " za cenę " + product.getPrice());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment