Java Reference
In-Depth Information
Magazine editions are added to a catalog using the Edition entity in which the
Edition id is set using the setId() method and the Edition date is set using
the setEdition() method. An Edition entity is persisted using the persist()
method and an Edition entity instance is flushed to the database using the flush()
method. Before we may add the Edition entity to the Catalog entity, we need to
merge the Catalog entity with the persistence context using the merge() method.
Subsequently, add the Edition entity to the Catalog entity with the
addEntity() method.
Edition edition = new Edition();
edition.setId(1022009);
edition.setEdition("January/February 2009");
em.persist(edition);
em.flush();
em.merge(catalog1);
catalog1.addEdition(edition);
A magazine edition has sections. Sections are created using the Section entity.
Section ID is set using the setId() method, and the section name is set using the
setSectionName() method. A Section entity is persisted using the persist()
method and an Edition entity is merged with the persistence context using
the merge() method. A Section entity is added to an Edition entity using the
addSection() method.
Section features = new Section();
features.setId("Oracle_Mag_Features_022009");
features.setSectionName("FEATURES");
em.persist(features);
em.merge(edition);
edition.addSection(features);
Create an Article entity using the new operator. Set the article ID using the setId()
method. Set the article title using the setTitle() method. Persist the Article entity
using the persist() method. Before adding an Article entity to a Section entity
merge the Section entity using the merge() method. Add an Article entity to a
Section entity using the addArticle() method. Invoke the flush() method to
flush the additions to the database.
Article article = new Article(features);
article.setId(12009);
article.setTitle(┬źLaunching Performance┬╗);
em.persist(article);
em.merge(features);
features.addArticle(article);
em.flush();
 
Search WWH ::




Custom Search