Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Foreign key not set in row of target table of target-one-to-one mapping

You must map the foreign key field in T2 to have it persisted, otherwise
there is no way for the field to be written.

Either define a OneToOne back from T2 to T1, or define a Basic/Direct
mapping for the field and ensure you set it when setting the T2 of the T1. 
Or, put the foreign key in T1 instead of T2. (I assume you are not using JPA
and JPA requires usage of a mappedBy to define a target foreign key
OneToOne, so must always be bi-directional).

There are other more elaborate ways, such as making T1 a multiple-table
descriptor mapping both T1 and T2 and make the T2 class an aggregate. 
EclipseLink does define a UnidirectionalOneToManyMapping that has the source
own the foriegn key and update it, but does not define a
UnidirectionalOneToOneMapping, perhaps log an enhancement request.


Rohit Banga-2 wrote:
> 
> Hi All
> 
> I have a unidirectional one-to-one mapping from T1 to T2. The foreign key
> is in T2, so I am using target foreign keys.
> Now when I add a new entity of T2 and link it to the source entity of T1
> using the following method, the foreign key is not being populated in the
> new row of T2.
> 
> t1.set("joinattr", t2);
> 
> The logs show just two SQL statements being executed - one to delete the
> orphan row (the relationship is private owned) and one to insert a new
> row. the insertion shows the binding for the direct mapped fields but
> since this mapping is unidirectional, I was expecting t1.set("joinattr",
> t2) to populate the foreign key in the target entity. But that does not
> happen.
> 
> Am I missing something here?
> 
> Thanks in Advance!
> Rohit
> Oracle Server Technologies
> 
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
Blog:  http://java-persistence-performance.blogspot.com/ Java Persistence
Performance 
-- 
View this message in context: http://old.nabble.com/Foreign-key-not-set-in-row-of-target-table-of-target-one-to-one-mapping-tp31462934p31497388.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top