Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jacobheric/867742 to your computer and use it in GitHub Desktop.
Save jacobheric/867742 to your computer and use it in GitHub Desktop.
Annotations based JPA entity persistence using Hibernate snippet
@Entity
public class Recipe implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
@Column(name = "brew_notes")
private String brewNotes;
private Timestamp start;
private Timestamp end;
@Column(name = "taste_notes")
private String tasteNotes;
@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
@JoinTable(name = "recipe_hops",
joinColumns = @JoinColumn(name = "recipe_id"),
inverseJoinColumns = @JoinColumn(name = "hop_id")
)
private Set<Hop> hops = new HashSet<Hop>();
@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
@JoinTable(name = "recipe_malts",
joinColumns = @JoinColumn(name = "recipe_id"),
inverseJoinColumns = @JoinColumn(name = "malt_id")
)
private Set<Malt> malts = new HashSet<Malt>();
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
private Yeast yeast;
/** snip **/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment