Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.53 KB | None | 0 0
  1. package entity;
  2.  
  3. import java.util.List;
  4.  
  5. import javax.persistence.Entity;
  6. import javax.persistence.GeneratedValue;
  7. import javax.persistence.GenerationType;
  8. import javax.persistence.Id;
  9. import javax.persistence.OneToMany;
  10.  
  11. @Entity
  12. public class Brand {
  13.  
  14.     @Id
  15.     @GeneratedValue(strategy=GenerationType.IDENTITY)
  16.     private int id;
  17.  
  18.     private String brand;
  19.    
  20.     @OneToMany(mappedBy="brand")
  21.     private List<Product> products;
  22.  
  23.     public int getId() {
  24.         return id;
  25.     }
  26.  
  27.     public void setId(int id) {
  28.         this.id = id;
  29.     }
  30.  
  31.     public String getBrand() {
  32.         return brand;
  33.     }
  34.  
  35.     public void setBrand(String brand) {
  36.         this.brand = brand;
  37.     }
  38.  
  39.     public List<Product> getProducts() {
  40.         return products;
  41.     }
  42.  
  43.     public void setProducts(List<Product> products) {
  44.         this.products = products;
  45.     }
  46.  
  47. }
  48.  
  49.  
  50. package entity;
  51.  
  52. import java.util.List;
  53.  
  54. import javax.persistence.Entity;
  55. import javax.persistence.GeneratedValue;
  56. import javax.persistence.GenerationType;
  57. import javax.persistence.Id;
  58. import javax.persistence.OneToMany;
  59.  
  60. @Entity
  61. public class Category {
  62.  
  63.     @Id
  64.     @GeneratedValue(strategy=GenerationType.IDENTITY)
  65.     private int id;
  66.  
  67.     private String country;
  68.  
  69.     @OneToMany(mappedBy="category")
  70.     private List<Product> products;
  71.  
  72.     public int getId() {
  73.         return id;
  74.     }
  75.  
  76.     public void setId(int id) {
  77.         this.id = id;
  78.     }
  79.  
  80.     public String getCountry() {
  81.         return country;
  82.     }
  83.  
  84.     public void setCountry(String country) {
  85.         this.country = country;
  86.     }
  87.  
  88.     public List<Product> getProducts() {
  89.         return products;
  90.     }
  91.  
  92.     public void setProducts(List<Product> products) {
  93.         this.products = products;
  94.     }
  95.  
  96. }
  97.  
  98.  
  99. package entity;
  100.  
  101. import java.util.List;
  102.  
  103. import javax.persistence.Entity;
  104. import javax.persistence.FetchType;
  105. import javax.persistence.GeneratedValue;
  106. import javax.persistence.GenerationType;
  107. import javax.persistence.Id;
  108. import javax.persistence.ManyToOne;
  109. import javax.persistence.OneToMany;
  110.  
  111. @Entity
  112. public class Product {
  113.  
  114.     @Id
  115.     @GeneratedValue(strategy = GenerationType.IDENTITY)
  116.     private int id;
  117.  
  118.     private String name;
  119.  
  120.     private double price;
  121.  
  122.     @ManyToOne(fetch = FetchType.LAZY)
  123.     private Category category;
  124.  
  125.     @ManyToOne(fetch = FetchType.LAZY)
  126.     private Brand brand;
  127.  
  128.     @ManyToOne(fetch = FetchType.LAZY)
  129.     private Size size;
  130.  
  131.     @OneToMany(mappedBy="product")
  132.     private List<UserOrder> userOrders;
  133.    
  134.     public List<UserOrder> getUserOrders() {
  135.         return userOrders;
  136.     }
  137.  
  138.     public void setUserOrders(List<UserOrder> userOrders) {
  139.         this.userOrders = userOrders;
  140.     }
  141.  
  142.     public int getId() {
  143.         return id;
  144.     }
  145.  
  146.     public void setId(int id) {
  147.         this.id = id;
  148.     }
  149.  
  150.     public String getName() {
  151.         return name;
  152.     }
  153.  
  154.     public void setName(String name) {
  155.         this.name = name;
  156.     }
  157.  
  158.     public double getPrice() {
  159.         return price;
  160.     }
  161.  
  162.     public void setPrice(double price) {
  163.         this.price = price;
  164.     }
  165.  
  166.     public Category getCategory() {
  167.         return category;
  168.     }
  169.  
  170.     public void setCategory(Category category) {
  171.         this.category = category;
  172.     }
  173.  
  174.     public Brand getBrand() {
  175.         return brand;
  176.     }
  177.  
  178.     public void setBrand(Brand brand) {
  179.         this.brand = brand;
  180.     }
  181.  
  182.     public Size getSize() {
  183.         return size;
  184.     }
  185.  
  186.     public void setSize(Size size) {
  187.         this.size = size;
  188.     }
  189. }
  190.  
  191.  
  192. package entity;
  193.  
  194. import java.util.List;
  195.  
  196. import javax.persistence.Entity;
  197. import javax.persistence.GeneratedValue;
  198. import javax.persistence.GenerationType;
  199. import javax.persistence.Id;
  200. import javax.persistence.OneToMany;
  201.  
  202. @Entity
  203. public class Role {
  204.     @Id
  205.     @GeneratedValue(strategy = GenerationType.IDENTITY)
  206.     private int id;
  207.  
  208.     private String role;
  209.  
  210.     @OneToMany(mappedBy="role")
  211.     private List<Usr> usrs;
  212.  
  213.     public int getId() {
  214.         return id;
  215.     }
  216.  
  217.     public void setId(int id) {
  218.         this.id = id;
  219.     }
  220.  
  221.     public String getRole() {
  222.         return role;
  223.     }
  224.  
  225.     public void setRole(String role) {
  226.         this.role = role;
  227.     }
  228.  
  229.     public List<Usr> getUsrs() {
  230.         return usrs;
  231.     }
  232.  
  233.     public void setUsrs(List<Usr> usrs) {
  234.         this.usrs = usrs;
  235.     }
  236.  
  237. }
  238.  
  239.  
  240. package entity;
  241.  
  242. import java.util.List;
  243.  
  244. import javax.persistence.Entity;
  245. import javax.persistence.GeneratedValue;
  246. import javax.persistence.GenerationType;
  247. import javax.persistence.Id;
  248. import javax.persistence.OneToMany;
  249.  
  250. @Entity
  251. public class Size {
  252.  
  253.     @Id
  254.     @GeneratedValue(strategy=GenerationType.IDENTITY)
  255.     private int id;
  256.  
  257.     private int size;
  258.  
  259.     @OneToMany(mappedBy="size")
  260.     private List<Product> products;
  261.  
  262.     public int getId() {
  263.         return id;
  264.     }
  265.  
  266.     public void setId(int id) {
  267.         this.id = id;
  268.     }
  269.  
  270.     public int getSize() {
  271.         return size;
  272.     }
  273.  
  274.     public void setSize(int size) {
  275.         this.size = size;
  276.     }
  277.  
  278.     public List<Product> getProducts() {
  279.         return products;
  280.     }
  281.  
  282.     public void setProducts(List<Product> products) {
  283.         this.products = products;
  284.     }
  285.  
  286. }
  287.  
  288.  
  289. package entity;
  290.  
  291. import java.util.List;
  292.  
  293. import javax.persistence.Entity;
  294. import javax.persistence.FetchType;
  295. import javax.persistence.GeneratedValue;
  296. import javax.persistence.GenerationType;
  297. import javax.persistence.Id;
  298. import javax.persistence.ManyToOne;
  299. import javax.persistence.OneToMany;
  300.  
  301. @Entity
  302. public class Usr {
  303.  
  304.     @Id
  305.     @GeneratedValue(strategy = GenerationType.IDENTITY)
  306.     private int id;
  307.  
  308.     private String username;
  309.  
  310.     private String email;
  311.  
  312.     private String password;
  313.  
  314.     @ManyToOne(fetch = FetchType.LAZY)
  315.     private Role role;
  316.    
  317.     @OneToMany(mappedBy="usr")
  318.     private List<UserOrder> userOrders;
  319.    
  320.     public List<UserOrder> getUserOrders() {
  321.         return userOrders;
  322.     }
  323.  
  324.     public void setUserOrders(List<UserOrder> userOrders) {
  325.         this.userOrders = userOrders;
  326.     }
  327.  
  328.     public int getId() {
  329.         return id;
  330.     }
  331.  
  332.     public void setId(int id) {
  333.         this.id = id;
  334.     }
  335.  
  336.     public String getUsername() {
  337.         return username;
  338.     }
  339.  
  340.     public void setUsername(String username) {
  341.         this.username = username;
  342.     }
  343.  
  344.     public String getEmail() {
  345.         return email;
  346.     }
  347.  
  348.     public void setEmail(String email) {
  349.         this.email = email;
  350.     }
  351.  
  352.     public String getPassword() {
  353.         return password;
  354.     }
  355.  
  356.     public void setPassword(String password) {
  357.         this.password = password;
  358.     }
  359.  
  360.     public Role getRole() {
  361.         return role;
  362.     }
  363.  
  364.     public void setRole(Role role) {
  365.         this.role = role;
  366.     }
  367.  
  368. }
  369.  
  370.  
  371. package entity;
  372.  
  373. import java.time.LocalDateTime;
  374.  
  375. import javax.persistence.Entity;
  376. import javax.persistence.FetchType;
  377. import javax.persistence.GeneratedValue;
  378. import javax.persistence.GenerationType;
  379. import javax.persistence.Id;
  380. import javax.persistence.ManyToOne;
  381.  
  382. @Entity
  383. public class UserOrder {
  384.  
  385.     @Id
  386.     @GeneratedValue(strategy = GenerationType.IDENTITY)
  387.     private int id;
  388.    
  389.     @ManyToOne(fetch = FetchType.LAZY)
  390.     private Usr usr;
  391.    
  392.     @ManyToOne(fetch = FetchType.LAZY)
  393.     private Product product;
  394.    
  395.     private LocalDateTime localDateTime;
  396.    
  397.     public int getId() {
  398.         return id;
  399.     }
  400.  
  401.     public void setId(int id) {
  402.         this.id = id;
  403.     }
  404.  
  405.     public LocalDateTime getLocalDateTime() {
  406.         return localDateTime;
  407.     }
  408.  
  409.     public void setLocalDateTime(LocalDateTime localDateTime) {
  410.         this.localDateTime = localDateTime;
  411.     }
  412.  
  413.     public Usr getUsr() {
  414.         return usr;
  415.     }
  416.  
  417.     public void setUsr(Usr usr) {
  418.         this.usr = usr;
  419.     }
  420.  
  421.     public Product getProduct() {
  422.         return product;
  423.     }
  424.  
  425.     public void setProduct(Product product) {
  426.         this.product = product;
  427.     }
  428.    
  429.    
  430. }
  431.  
  432.  
  433. package Controler;
  434.  
  435. import javax.persistence.EntityManager;
  436. import javax.persistence.EntityManagerFactory;
  437. import javax.persistence.Persistence;
  438.  
  439. public class Main {
  440.  
  441.     public static void main(String[] args) {
  442.         EntityManagerFactory factory = Persistence
  443.                 .createEntityManagerFactory("primary");
  444.         EntityManager em = factory.createEntityManager();
  445.         em.close();
  446.         factory.close();
  447.     }
  448.  
  449. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement