Update Bar.java
This commit is contained in:
parent
730ebd57af
commit
80cb34833c
@ -1,26 +1,15 @@
|
|||||||
package org.baeldung.persistence.model;
|
package org.baeldung.persistence.model;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.Set;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.*;
|
||||||
import javax.persistence.Entity;
|
import org.hibernate.annotations.OrderBy;
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.GenerationType;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
@NamedQuery(name = "Bar.findAll", query = "SELECT b FROM Bar b")
|
||||||
public class Bar implements Serializable {
|
public class Bar implements Serializable {
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
|
||||||
private long id;
|
|
||||||
|
|
||||||
@Column(nullable = false)
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private List<Foo> foos;
|
|
||||||
|
|
||||||
public Bar() {
|
public Bar() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@ -31,28 +20,42 @@ public class Bar implements Serializable {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// API
|
private static final long serialVersionUID = 1L;
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
private int id;
|
||||||
|
|
||||||
public long getId() {
|
private String name;
|
||||||
return id;
|
|
||||||
|
@OneToMany(mappedBy = "bar", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
|
@OrderBy(clause = "NAME DESC")
|
||||||
|
Set<Foo> fooSet = Sets.newHashSet();
|
||||||
|
|
||||||
|
//API
|
||||||
|
|
||||||
|
public Set<Foo> getFooSet() {
|
||||||
|
return fooSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(final long id) {
|
public void setFooList(Set<Foo> fooSet) {
|
||||||
|
this.fooSet = fooSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(final String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Foo> getFooList() {
|
|
||||||
return foos;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -83,8 +86,9 @@ public class Bar implements Serializable {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
builder.append("Foo [name=").append(name).append("]");
|
builder.append("Bar [name=").append(name).append("]");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user