Advertisement
inline_five

Country.java

Feb 25th, 2025
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. package com.d288.mwise60.entities;
  2.  
  3. import jakarta.persistence.*;
  4. import lombok.Data;
  5. import lombok.Getter;
  6. import lombok.Setter;
  7. import org.hibernate.annotations.CreationTimestamp;
  8. import org.hibernate.annotations.UpdateTimestamp;
  9.  
  10. import java.util.Date;
  11. import java.util.HashSet;
  12. import java.util.Set;
  13.  
  14. @Entity
  15. @Table(name = "countries")
  16. @Getter
  17. @Setter
  18.  
  19. public class Country {
  20.  
  21.     @Id
  22.     @GeneratedValue(strategy = GenerationType.IDENTITY)
  23.     @Column(name = "country_id")
  24.     private Long id; // SQL refers to it as "country_id"
  25.  
  26.     // temp workaround for Division class not accessing the lombok getters
  27.     public Long getId() {
  28.         return id;
  29.     }
  30.  
  31.     @Column(name = "country")
  32.     private String country_name; // SQL refers to it as "country"
  33.  
  34.     @CreationTimestamp // hibernate manages grabbing time
  35.     @Column(name = "create_date")
  36.     private Date create_date;
  37.  
  38.     @UpdateTimestamp
  39.     @Column(name = "last_update") // hibernate manages grabbing time
  40.     private Date last_update;
  41.  
  42.     @OneToMany(cascade = CascadeType.ALL, mappedBy = "country") // SQL refers to it as "country_id"
  43.     private Set<Division> divisions = new HashSet<>();
  44.  
  45.  
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement