Transitive persistence objects you wish to delete the code that removes an element from the collection is often in a different layer than the code that executes the delete() operation. With orphan deletion enabled, you can remove orphans from the collection, and Hibernate will assume that they re no longer referenced by any other entity. Note again that orphan deletion is implicit if you map a collection of components; the extra option is relevant only for a collection of entity references (almost always a ). Java Persistence and EJB 3.0 also support transitive state changes across entity associations. The standardized cascading options are similar to Hibernate s, so you can learn them easily. 12.1.4 Transitive associations with JPA The Java Persistence specification supports annotations for entity associations that enable cascading object manipulation. Just as in native Hibernate, each Entity- Manager operation has an equivalent cascading style. For example, consider the Category tree (parent and children associations) mapped with annotations: @Entity public class Category { private String name; @ManyToOne public Category parentCategory; @OneToMany(mappedBy = “parentCategory”, cascade = { CascadeType.PERSIST, CascadeType.MERGE } ) public Set childCategories = new HashSet(); … } You enable standard cascading options for the persist() and merge() operations. You can now create and modify Category instances in persistent or detached state, just as you did earlier with native Hibernate: Category computer = … // Loaded in a previous persistence context Category laptops = new Category(”Laptops”); Category laptopUltraPortable = new Category(”Ultra-Portable”); Category laptopTabletPCs = new Category(”Tablet PCs”); laptops.addChildCategory(laptopUltraPortable); laptops.addChildCategory(laptopTabletPCs); computer.setName(”Desktops and Laptops”); computer.addChildCategory(laptops);
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.
This entry was posted
on Monday, December 17th, 2007 at 6:06 am and is filed under j2ee.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.