Skip to content

Instantly share code, notes, and snippets.

@nemo83
Last active December 15, 2015 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nemo83/5276363 to your computer and use it in GitHub Desktop.
Save nemo83/5276363 to your computer and use it in GitHub Desktop.
@Entity
@Table(name ="product")
public class Product {
private Integer id;
private String name;
private List<ProductItem> productItems =new LinkedList<ProductItem>();
public Product() {
}
@Id
@GenericGenerator(name ="generator", strategy ="increment")
@GeneratedValue(generator ="generator")
@Column(name ="product_id", nullable =false)
public Integer getId() {
returnthis.id;
}
publicvoid setId(Integer id) {
this.id = id;
}
@Column(name ="name")
public String getName() {
returnthis.name;
}
publicvoid setName(String name) {
this.name = name;
}
/*
* Here is the annotation to add in order to
* Hibernate to automatically insert and update
* ProducItems (if any)
*/
@OneToMany(fetch = FetchType.LAZY, mappedBy ="pk.product", cascade =
{CascadeType.PERSIST, CascadeType.MERGE})
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
public List<ProductItem> getProductItems() {
returnthis.productItems;
}
publicvoid setProductItems(List<ProductItem> productItems) {
this.productItems = productItems;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment