Last active
December 15, 2015 14:39
-
-
Save nemo83/5276363 to your computer and use it in GitHub Desktop.
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
@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