Skip to content

Instantly share code, notes, and snippets.

@tturner
Created November 3, 2010 23:59
Show Gist options
  • Save tturner/661920 to your computer and use it in GitHub Desktop.
Save tturner/661920 to your computer and use it in GitHub Desktop.
Bidirectional JPA OneToMany and Yaml loader
Class One:
@Entity
public class Sweet extends GenericModel implements java.io.Serializable {
@Id
@Column(unique = true, nullable = false, insertable = true, updatable = true)
public String name;
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, targetEntity = Bag.class)
public Bag bag;
}
Class Two:
@Entity
public class Bag extends Model implements java.io.Serializable {
public String name;
@OneToMany(cascade = CascadeType.ALL, targetEntity = Sweet.class, mappedBy = "bag")
public List<Sweet> sweets;
}
Yaml file:
Bag(thisbag):
name: bagone
Sweet(first):
name: sweetone
bag: thisbag
Sweet(second):
name: sweettwo
bag: thisbag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment