Transitive persistence As you can see, several cascading options can be combined and applied to a particular association as a comma-separated list. Further note that delete-orphan isn t included in all. Cascading options are declared with annotations in two possible ways. First, all the association mapping annotations, @ManyToOne, @OneToOne, @OneToMany, and @ManyToMany, support a cascade attribute. The value of this attribute is a single or a list of javax.persistence.CascadeType values. For example, the XML illustrative mapping done with annotations looks like this: @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }) @JoinColumn(name = “PARENT_CATEGORY_ID”, nullable = true) private Category parent; … @OneToMany(cascade = CascadeType.ALL) private Set bids = new HashSet(); Obviously, not all cascading types are available in the standard javax.persistence package. Only cascading options relevant for EntityManager operations, such as persist() and merge(), are standardized. You have to use a Hibernate extension annotation to apply any Hibernate-only cascading option: @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }) @org.hibernate.annotations.Cascade( org.hibernate.annotations.CascadeType.SAVE_UPDATE ) @JoinColumn(name = “PARENT_CATEGORY_ID”, nullable = true) private Category parent; … @OneToOne @org.hibernate.annotations.Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.LOCK }) @PrimaryKeyJoinColumn private Address shippingAddress; … @OneToMany(cascade = CascadeType.ALL) @org.hibernate.annotations.Cascade( org.hibernate.annotations.CascadeType.DELETE_ORPHAN ) private Set bids = new HashSet();
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.
This entry was posted
on Sunday, December 9th, 2007 at 6:17 pm 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.