Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Strange Behavior with One-To-One Mapping - Insert Query Doubt

Hi All

I tried the following with eclipselink build 9156.

There are two tables u1 and u3. u1 has fields a1, b1 with a1 as the primary key and u3 has fields a3, b3 with a3 as the primary key. There is a DynamicType corresponding to both u1 and u3.
Create a target-one-to-one mapping from u1 to u3 with the u3.a3 as the foreign key. Create a one-to-one mapping from u3 to u1 for the back reference.

Now let us assume that there is an entity (E1) of type u1 having the following values - a1='a1_val' and b1='b1_val'. The corresponding entity (E2) linked by the target-one-to-one mapping in a3 has the value a3='a1_val' (foreign key constraint) and b3='b3_val'.

I create a new dynamic entity (E3) of type u3 with a3='a3_new_row' and b3='b3_new_row'. Now I establish the link between E1 and E3 by setting the value of join attribute for both the one-to-one mappings to the respective entities. The following two SQL queries are generated as a result. uow.commit() does not throw an error.

INSERT INTO u3 (b3, a3) VALUES (?, ?)
       bind => [b3_new_row, a1_val]

DELETE FROM u3 WHERE (a3 = ?)
       bind => [a1_val]

The second query deletes the row inserted by the first query.

I have two doubts here:

1. I provided the value for a3 as 'a3_new_row'. This value is ignored to ensure that the foreign key is populated created properly. Is this expected behavior? Shouldn't eclipselink throw an error for such a situation?

2. After the transaction commits when I issue a ReadAllQuery (with the _expression_ specifying the value of the primary alone so that there is a cache hit). The value of a3 is returned as 'a3_new_row' and that of b3 as 'b3_new_row'. If I restart my program so that there is no cache in place now, the ReadAllQuery (with a left outer join) obviously does not return any entity for u3 as there is no link between u1 and u3 in the database tables. The row in U3 was deleted by the SQL above. Is this a bug or am I missing something?

3. The first INSERT should fail as I already have a row in u3 that has the value of a3 (primary key) as 'a1_val'. Since the back reference one-to-one mapping has privately owned property set to false, eclipselink did not issue a delete for the row that was already existing. But in this case the INSERT should not go through fine. I do not see any exception in my eclipselink logs with logging level set to finest.

Thanks for your help!

--
Thanks and Regards
Rohit Banga
Member Technical Staff
Oracle Server Technologies

Back to the top