Commit 88e70a7a by Patryk Czarnik

Adnotacje jakarta.validation

parent c17065bb
package sklep.model; package sklep.model;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.Pattern;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
...@@ -10,6 +12,7 @@ import java.util.Set; ...@@ -10,6 +12,7 @@ import java.util.Set;
public class Customer { public class Customer {
@Id @Id
@Column(name = "customer_email", nullable = false, length = 100) @Column(name = "customer_email", nullable = false, length = 100)
@Email
private String customerEmail; private String customerEmail;
@Column(name = "customer_name", nullable = false, length = 100) @Column(name = "customer_name", nullable = false, length = 100)
...@@ -22,6 +25,7 @@ public class Customer { ...@@ -22,6 +25,7 @@ public class Customer {
private String address; private String address;
@Column(name = "postal_code", length = 10) @Column(name = "postal_code", length = 10)
@Pattern(regexp="[0-9]{2}-[0-9]{3}")
private String postalCode; private String postalCode;
@Column(name = "city", length = 100) @Column(name = "city", length = 100)
......
package sklep.model; package sklep.model;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.validation.constraints.Min;
import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.ColumnDefault;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -23,6 +25,7 @@ public class OrderProduct { ...@@ -23,6 +25,7 @@ public class OrderProduct {
@ColumnDefault("1") @ColumnDefault("1")
@Column(name = "quantity", nullable = false) @Column(name = "quantity", nullable = false)
@Min(1)
private Short quantity; private Short quantity;
@Column(name = "actual_price", nullable = false, precision = 10, scale = 2) @Column(name = "actual_price", nullable = false, precision = 10, scale = 2)
......
package sklep.model; package sklep.model;
import jakarta.persistence.*;
import org.hibernate.annotations.ColumnDefault;
import java.math.BigDecimal; import java.math.BigDecimal;
import jakarta.persistence.*;
import jakarta.validation.constraints.*;
@Entity @Entity
@Table(name = "products") @Table(name = "products")
@NamedQuery(name="Product.findAll", query="SELECT p FROM Product p ORDER BY p.id") @NamedQuery(name="Product.findAll", query="SELECT p FROM Product p ORDER BY p.id")
...@@ -15,12 +15,17 @@ public class Product { ...@@ -15,12 +15,17 @@ public class Product {
private Integer id; private Integer id;
@Column(name = "product_name", nullable = false, length = 100) @Column(name = "product_name", nullable = false, length = 100)
@NotBlank
@Size(min=1, max=20)
private String productName; private String productName;
@Column(name = "price", nullable = false, precision = 10, scale = 2) @Column(name = "price", nullable = false, precision = 10, scale = 2)
@DecimalMin("0.01")
@DecimalMax("99999.99")
private BigDecimal price; private BigDecimal price;
@Column(name = "vat", precision = 2, scale = 2) @Column(name = "vat", precision = 2, scale = 2)
@Min(0)
private BigDecimal vat; private BigDecimal vat;
@Column(name = "description", length = Integer.MAX_VALUE) @Column(name = "description", length = Integer.MAX_VALUE)
......
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