Advertisement
inline_five

Division.java

Feb 25th, 2025
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 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 = "divisions")
  16. @Getter
  17. @Setter
  18.  
  19. public class Division {
  20.  
  21.     // start adding variables next
  22.     @Id
  23.     @GeneratedValue(strategy = GenerationType.IDENTITY)
  24.     @Column(name = "division_id")
  25.     private Long id;
  26.  
  27.     @Column(name = "division")
  28.     private String division_name; // SQL refers to it as "division"
  29.  
  30.     @CreationTimestamp // hibernate manages grabbing time
  31.     @Column(name = "create_date")
  32.     private Date create_date;
  33.  
  34.     @UpdateTimestamp
  35.     @Column(name = "last_update") // hibernate manages grabbing time
  36.     private Date last_update;
  37.  
  38.     @ManyToOne(fetch = FetchType.LAZY)
  39.     @JoinColumn(name = "country_id", nullable = false, insertable = false, updatable = false) // joins country_id column in countries table
  40.     private Country country;
  41.  
  42.     @Column(name = "country_id")
  43.     private Long country_ID; // may be lower case country_id
  44.  
  45.     @OneToMany(cascade = CascadeType.ALL, mappedBy = "division") // Referenced as "division" in the Customer entity
  46.     private Set<Customer> customers = new HashSet<>(); // initializes as eager (not lazy)
  47.  
  48.     // unsure what to do here
  49.     public void setCountry(Country country) {
  50.         this.country = country;
  51.         this.country_ID = country.getId();
  52.         //setCountry_ID(country.getId());
  53.     }
  54.  
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement