Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Bidirectional one-to-one relations with dynamic entities
Bidirectional one-to-one relations with dynamic entities [message #1111425] Wed, 18 September 2013 07:44 Go to next message
Xander Uiterlinden is currently offline Xander UiterlindenFriend
Messages: 6
Registered: July 2009
Junior Member

In our project we're using eclipse link dynamic entities. These are defined using a DynamicTypeBuilder.
When using 'normal' entities you can create a bidirectional one-to-one relation using @OneToOne on one end of the association and @MappedBy on the other end.
What is the equivalent of this using the DynamicTypeBuilder ? It does provide a addOneToOneMapping(...) method, but I can't really find the equivalent of the @MappedTo.
An example would be really helpful.


Re: Bidirectional one-to-one relations with dynamic entities [message #1111702 is a reply to message #1111425] Wed, 18 September 2013 15:51 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1342
Registered: July 2009
Senior Member
The mappedby causes the annotation processor to create a regular OneToOne mapping, pulling the relationship from the other side, reversing the source and foreign keys. Since the target is in the current table, it isn't considered writable from this mapping. Unfortunately the DynamicTypeBuilder does not have a convenient method to do the same, so you would have to create your own OneToOneMapping instance and pass it to the addMapping method, similar to how the addOneToOneMapping works. Something like:
        OneToOneMapping mapping = new OneToOneMapping();
        mapping.addTargetForeignKeyFieldName(targetsFKFieldName, sourcesPKFieldName);

If there is a composite pk, you will need to add a foreign key for each field. The addOneToOneMapping takes in the current type's foreign key fields and looks up the target's primary key field values, but you might be able to get both target and source fields from the mapping in the other side (if you have a mapped by name, and that mapping was already created) using:

        Map<DatabaseField, DatabaseField> map = ((OneToOneMapping)refType.getDescriptor().getMappingForAttributeName(mappedByName)).getSourceToTargetKeyFields();
        for (DatabaseField fk : map.keySet()) {
            mapping.addTargetForeignKeyField(fk, (DatabaseField)map.get(fk));

Best Regards,

[Updated on: Wed, 18 September 2013 15:52]

Report message to a moderator

Previous Topic:Cascade.remove performance suggestions
Next Topic:Implementing XMLNameTransformer breaks JSON mapping of abstract classes
Goto Forum:

Current Time: Tue Mar 31 11:15:34 GMT 2020

Powered by FUDForum. Page generated in 0.02822 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top