Update Bar.java

This commit is contained in:
egmp777 2014-05-09 15:51:04 -05:00
parent 80cb34833c
commit 82ccad7146
1 changed files with 27 additions and 21 deletions

View File

@ -1,13 +1,13 @@
package org.baeldung.persistence.model; package org.baeldung.persistence.model;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType; import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.CascadeType;
@Entity @Entity
public class Bar implements Serializable { public class Bar implements Serializable {
@ -19,7 +19,9 @@ public class Bar implements Serializable {
@Column(nullable = false) @Column(nullable = false)
private String name; private String name;
private List<Foo> foos; @OneToMany(mappedBy = "bar", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@OrderBy("name ASC")
List<Foo> fooList;
public Bar() { public Bar() {
super(); super();
@ -50,7 +52,11 @@ public class Bar implements Serializable {
} }
public List<Foo> getFooList() { public List<Foo> getFooList() {
return foos; return fooList;
}
public void setFooList(final List<Foo> fooList) {
this.fooList = fooList;
} }
// //
@ -83,7 +89,7 @@ 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();
} }