Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.d288.mwise60.entities;
- import jakarta.persistence.*;
- import lombok.Data;
- import lombok.Getter;
- import lombok.Setter;
- import org.hibernate.annotations.CreationTimestamp;
- import org.hibernate.annotations.UpdateTimestamp;
- import java.util.Date;
- import java.util.HashSet;
- import java.util.Set;
- @Entity
- @Table(name = "divisions")
- @Getter
- @Setter
- public class Division {
- // start adding variables next
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- @Column(name = "division_id")
- private Long id;
- @Column(name = "division")
- private String division_name; // SQL refers to it as "division"
- @CreationTimestamp // hibernate manages grabbing time
- @Column(name = "create_date")
- private Date create_date;
- @UpdateTimestamp
- @Column(name = "last_update") // hibernate manages grabbing time
- private Date last_update;
- @ManyToOne(fetch = FetchType.LAZY)
- @JoinColumn(name = "country_id", nullable = false, insertable = false, updatable = false) // joins country_id column in countries table
- private Country country;
- @Column(name = "country_id")
- private Long country_ID; // may be lower case country_id
- @OneToMany(cascade = CascadeType.ALL, mappedBy = "division") // Referenced as "division" in the Customer entity
- private Set<Customer> customers = new HashSet<>(); // initializes as eager (not lazy)
- // unsure what to do here
- public void setCountry(Country country) {
- this.country = country;
- this.country_ID = country.getId();
- //setCountry_ID(country.getId());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement