|
| 1 | +package org.baeldung.persistence.model; |
| 2 | + |
| 3 | +import java.io.Serializable; |
| 4 | +import java.util.List; |
| 5 | + |
| 6 | +import javax.persistence.Column; |
| 7 | +import javax.persistence.Entity; |
| 8 | +import javax.persistence.GeneratedValue; |
| 9 | +import javax.persistence.GenerationType; |
| 10 | +import javax.persistence.Id; |
| 11 | + |
| 12 | +@Entity |
| 13 | +public class Bar implements Serializable { |
| 14 | + |
| 15 | + @Id |
| 16 | + @GeneratedValue(strategy = GenerationType.AUTO) |
| 17 | + private long id; |
| 18 | + |
| 19 | + @Column(nullable = false) |
| 20 | + private String name; |
| 21 | + |
| 22 | + private List<Foo> foos; |
| 23 | + |
| 24 | + public Bar() { |
| 25 | + super(); |
| 26 | + } |
| 27 | + |
| 28 | + public Bar(final String name) { |
| 29 | + super(); |
| 30 | + |
| 31 | + this.name = name; |
| 32 | + } |
| 33 | + |
| 34 | + // API |
| 35 | + |
| 36 | + public long getId() { |
| 37 | + return id; |
| 38 | + } |
| 39 | + |
| 40 | + public void setId(final long id) { |
| 41 | + this.id = id; |
| 42 | + } |
| 43 | + |
| 44 | + public String getName() { |
| 45 | + return name; |
| 46 | + } |
| 47 | + |
| 48 | + public void setName(final String name) { |
| 49 | + this.name = name; |
| 50 | + } |
| 51 | + |
| 52 | + public List<Foo> getFooList() { |
| 53 | + return foos; |
| 54 | + } |
| 55 | + |
| 56 | + // |
| 57 | + |
| 58 | + @Override |
| 59 | + public int hashCode() { |
| 60 | + final int prime = 31; |
| 61 | + int result = 1; |
| 62 | + result = prime * result + ((name == null) ? 0 : name.hashCode()); |
| 63 | + return result; |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + public boolean equals(final Object obj) { |
| 68 | + if (this == obj) |
| 69 | + return true; |
| 70 | + if (obj == null) |
| 71 | + return false; |
| 72 | + if (getClass() != obj.getClass()) |
| 73 | + return false; |
| 74 | + final Bar other = (Bar) obj; |
| 75 | + if (name == null) { |
| 76 | + if (other.name != null) |
| 77 | + return false; |
| 78 | + } else if (!name.equals(other.name)) |
| 79 | + return false; |
| 80 | + return true; |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public String toString() { |
| 85 | + final StringBuilder builder = new StringBuilder(); |
| 86 | + builder.append("Foo [name=").append(name).append("]"); |
| 87 | + return builder.toString(); |
| 88 | + } |
| 89 | + |
| 90 | +} |
0 commit comments