Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Andras Madi-Szabo
Added: May 2, 2020 1:12 PM
Views: 127
Tags: no tags
  1. package com.greenfox.matrev_rebuild.models;
  2.  
  3. import java.util.Date;
  4. import javax.persistence.Entity;
  5. import javax.persistence.FetchType;
  6. import javax.persistence.GeneratedValue;
  7. import javax.persistence.GenerationType;
  8. import javax.persistence.Id;
  9. import javax.persistence.JoinColumn;
  10. import javax.persistence.ManyToOne;
  11. import javax.persistence.SequenceGenerator;
  12. import javax.persistence.Temporal;
  13. import javax.persistence.TemporalType;
  14. import lombok.Data;
  15. import lombok.Getter;
  16. import lombok.Setter;
  17.  
  18. @Getter
  19. @Setter
  20.  
  21. @SequenceGenerator(name = "seq", initialValue = 2, allocationSize = 50)
  22. public class Car {
  23.   @Id
  24.   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq")
  25.   private long id;
  26.   private  String brand;
  27.   private int speed;
  28.   @Temporal(TemporalType.DATE)
  29.   private Date date;
  30.   @ManyToOne(fetch = FetchType.EAGER)
  31.   @JoinColumn
  32.   private Owner owner;
  33.  
  34.   public Car() {
  35.     this.date = new Date();
  36.   }
  37.  
  38.   public Car(String brand, int speed) {
  39.     this.brand = brand;
  40.     this.speed = speed;
  41.     this.date = new Date();
  42.   }
  43. }
  44.