In your first example, you'll end up adding a new row to the B table
each time you do the new assignment -- you'll see an INSERT statement
each time the code executes.

In the second, you'll end up updating a single row in the B table each
time -- you'll see an UPDATE statement.

You could also set up the relation such that your first example would
result in a DELETE for the old row and an INSERT for the new row. You
would do this with the @Dependent annotation.

-Patrick

On Nov 6, 2007 7:34 PM, Gul Onural <[EMAIL PROTECTED]> wrote:
>
> Let say I have classB inside classA, both are @Entity and @OneToOne
> relationships between the two.
>
> Let say I already persisted classA and classB and I want to update
> variable b of the ClassA using following code.
>
> I am trying to understand if the database effect of assigning a "new"
> ClassB to variable b (Code piece-I below) is any different than
> getting b first than updating B's member variables (Code piece -II) ?
>
> // Pseudo code piece - I
> startTransaction
>     X = findClassA
>     X.setb(new ClassB)
> commitTransaction
>
> // Pseudo code piece - II
> startTransaction
>     X = findClassA
>     X.getb.setName("...)
> commitTransaction
>
> public class ClassA {
>      int idA;
>      @OneToMany(mappedBy = "myA", cascade = CascadeType.ALL,
> targetEntity = classB, fetch = FetchType.EAGER)
>      ClassB b;
>      String name;
>      ...
> }
>
> public class ClassB {
>   int idB
>   @OneToOne
>   @JoinColumn(name = "idA")
>   private ClassA myA;
>    ....
> }
>
>
>



-- 
Patrick Linskey
202 669 5907

Reply via email to