diff --git a/Doc/Sda1/Ref/src/rdbms2catalog.jpa.skeleton.zip b/Doc/Sda1/Ref/src/rdbms2catalog.jpa.skeleton.zip index b5d18f792c525ad17a67d58a289beb0be7205051..50ae5f1b69797913c10a10bec021afac30693d9f 100644 Binary files a/Doc/Sda1/Ref/src/rdbms2catalog.jpa.skeleton.zip and b/Doc/Sda1/Ref/src/rdbms2catalog.jpa.skeleton.zip differ diff --git a/Doc/Sda1/jpaintro.xml b/Doc/Sda1/jpaintro.xml index 546cb109e75e1570a0f07d7a83c333a8514326e2..58135b4723130b0ab6620c39ed38d985bdca8b2e 100644 --- a/Doc/Sda1/jpaintro.xml +++ b/Doc/Sda1/jpaintro.xml @@ -361,63 +361,15 @@ CREATE TABLE `Lecture` ( <classname>de.hdm_stuttgart.mi.sda1.sql2catalog.model.Description</classname>.</para> <tip> - <orderedlist> - <listitem> - <para>Since <xref linkend="glo_JPA"/> requires an - <code>@id</code> you must provide it. Though composite - <code>@id</code>'s are possible you better define an - additional (business) unique constraint by:</para> - - <programlisting language="none">@Table( - uniqueConstraints= - @UniqueConstraint(columnNames={"product", "orderIndex"}) - ) -@Entity -public class Description { ...</programlisting> - </listitem> - - <listitem> - <para>The required <code>@ManyToOne</code> annotation - will result in a SQL schema property - <property>product_id</property>. This may be renamed to - <property>product</property> by adding - <code>@JoinColumn(name="product")</code>.</para> - </listitem> - - <listitem> - <para>Adding @OneToMany(mappedBy = "product", <emphasis - role="bold">cascade=CascadeType.ALL</emphasis>) allows - for transitive persistence of dependent - <classname>de.hdm_stuttgart.mi.sda1.sql2catalog.model.Description</classname> - entities.</para> - </listitem> - </orderedlist> + <para>Since <classname>Description</classname> instances are + composites with respect to <classname>Product</classname> + you might want to use @ElementCollection in favour of + @ManyToOne / @OneToMany.</para> </tip> - <para>A correct implementation should allow for enabling - <classname>rdbms2catalog.TestSchema</classname> by - uncommenting the test method's body. </para> - </listitem> - - <listitem> - <para>Write a second <productname>Junit</productname> test - class checking for uniqueness of - (<property>product</property>, - <property>itemOrder</property>). Using duplicates should yield - an exception which may be accounted for by using:</para> - - <programlisting language="none">public class TestSchemaConflict { -... - @Test(expected= ...Exception.class) - public void insertData() { - { - final EntityTransaction transaction = em.getTransaction(); - transaction.begin(); - - final Product monkeyPickedTea = new Product(1, "Monkey Picked Tea", null); - new Description(monkeyPickedTea, 0, "Picked only by specially trained monkeys"); - new Description(monkeyPickedTea, 0, "Rare wild Chinese tea"); // oops! Unique key violation -...</programlisting> + <para>Test your implementation by uncommenting the test + method's body in + <classname>rdbms2catalog.TestSchema</classname>.</para> </listitem> <listitem> diff --git a/P/Sda1/Jpa/rdbms2catalog/skeleton/src/test/java/rdbms2catalog/TestSchema.java b/P/Sda1/Jpa/rdbms2catalog/skeleton/src/test/java/rdbms2catalog/TestSchema.java index b5f12855e9d63af5425ff56cf7f2f3c8947ebd46..27ba0ee1b3be31e1fa49c40ce74ac1287e90d0ad 100644 --- a/P/Sda1/Jpa/rdbms2catalog/skeleton/src/test/java/rdbms2catalog/TestSchema.java +++ b/P/Sda1/Jpa/rdbms2catalog/skeleton/src/test/java/rdbms2catalog/TestSchema.java @@ -27,16 +27,13 @@ public class TestSchema { // accordingly the following commented code should work. // final Product monkeyPickedTea = new Product(1, "Monkey Picked Tea", null); -// new Description(monkeyPickedTea, 0, "Picked only by specially trained monkeys"); -// new Description(monkeyPickedTea, 1, "Rare wild Chinese tea"); +// monkeyPickedTea.getDescriptions().add(new Description("Picked by specially trained monkeys")); +// monkeyPickedTea.getDescriptions().add(new Description("Rare wild Chinese tea")); // // final Product instantTent = new Product(2, "4-Person Instant Tent", 15); -// new Description(instantTent, 0, "Exclusive WeatherTec system."); -// new Description(instantTent, 1, "4-person, 1-compartment tent"); -// new Description(instantTent, 2, "Pre-attached tent poles"); -// -// em.persist(monkeyPickedTea); -// em.persist(instantTent); +// instantTent.getDescriptions().add(new Description("Exclusive WeatherTec system.")); +// instantTent.getDescriptions().add(new Description("4-person, 1-compartment tent")); +// instantTent.getDescriptions().add(new Description("Pre-attached tent poles")); transaction.commit(); }