Created
November 3, 2010 23:59
-
-
Save tturner/661920 to your computer and use it in GitHub Desktop.
Bidirectional JPA OneToMany and Yaml loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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