Hi All,
I would value your expertise on explaining how this JPA ManyToMany code (chapter 5) example below from
Java EE 5 with Netbeans 6 book:
What I am not clear about is the following area in create() of CustomerOrderJpaController where there appears to be a lot of re-assigning of entity data back to itself:
( i ) Why is there a need to locate the customer entity with em.getReference() on line 21 when the value has already been found on line 19 (ManyToOne with CustomerOrder owning)?
( ii ) What is the purpose of lines 25 – 27 and especially why is variable itemCollectionItemToAttach being re-assigned to all items found in itself (line 26)? Is it assembling a list of new items to be included into this customerOrder entity object? (ManyToMany – CustomerOrder owning)
( iii ) Why not use em.find() instead of em.getReference()? I thought em.find() is better because it returns NULL when there are no record found and it doesn’t throw an exception?
I am running JDK 1.6.0_23, NB6.9.1, GF 2.1 (Java EE 5) on Windows XP.
Your feedback would be much appreciated to enlightening in this key yet complex technology.
Thanks in advance,
Jack