Yes, that's right. listener1 will capture that (mappedBy="foo")
has been added. From that point (until the "mappedBy" field is
removed), the MappedByJoiningStrategy will be non-null and
listener2 will capture changes to the attribute name itself.
Cheers,
- Paul
Dimov, Stefan wrote:
Hey, Paul,
I got it - listener1 solves my issue!
Best wishes!
Stefan Dimov
Hey Paul,
10x 4 the info. It helped. But not entirely. Now
I have another issue.
Let's say that I have an attribute annotated
with @OneToOne. If I add to this annotation (mappedBy="someAttr"),
which is the listener and where I have to add it in order to catch that
change? The listener2 you describe below doesn't work, because the
joining strategy of the relationship reference of the corresponding
attribute is null and I can't add a reference to it.
Best wishes!
Stefan Dimov
Hey Stefan,
This area has seen significant churn this past release in order to
support extensibility, but it has also improved some UI functionality
as well.
A RelationshipMapping now has a RelationshipReference
that describes how the two entities involved are joined across the
relationship. A RelationshipReference has a predominant
joining strategy that may, among other things, be a join table, join
columns, or it may specify the joining to be controlled by the other
side of the relationship (mappedBy). When it is mapped by the other
side of the relationship, the predominant joining strategy is a MappedByJoiningStrategy
and that joining strategy has the property MAPPED_BY_ATTRIBUTE_PROPERTY
that you are used to looking for on the mapping itself.
In other words, you may do the following:
((RelationshipMapping)
JavaPersistentAttribute.getMapping()).getRelationshipReference().addPropertyChangeListener(RelationshipReference.PREDOMINANT_JOINING_STRATEGY_PROPERTY,
listener1);
where listener1 is listening for changes to the joining
strategy. That is, this property change will signal whether the
mapping is now using a join table rather than join columns, for
instance, but will not give change notification to the inner workings
of the joining strategy. ((As an aside, I'd recommend using a targeted
listener (using the property name while adding the change listener)
instead of the anonymous method you chose. The name of the property
(or list or collection) gives clues as to what type of change event it
is, and the interface where it is located tells you on which object to
register the listener.)) At any rate, once you know you have a MappedByJoiningStrategy
you may then do:
MappedByJoiningStrategy.addPropertyChangeListener(MappedByJoiningStrategy.MAPPED_BY_ATTRIBUTE_PROPERTY,
listener2);
where listener2 is listening for changes in the actual attribute.
Hope this helps,
- Paul
--
Paul Fullbright
Eclipse Java Persistence Tools (Dali) Development
Oracle
Dimov, Stefan wrote:
Hi, all,
In SAP NWDS I'm
working on a tool which needs to know if the 'mappedBy' attribute of
the annotation of the owned side of a bi-directional relation has been
changed. In order to do that, I'm adding a listener to the owned side
relation attribute by using:
JavaPersistentAttribute.getMapping().addPropertyChangeListener(lsnr)
But the specified
listener doesn't get any events when I change the mappedBy attribute in
the java code.
It was working in
the old DALI, but now when we adopted our NWDS to the new DALI it's not
working anymore.
Am I using the
wrong kind of listener or do I have to open a bug in the bugzilla?
Best wishes!
Stefan Dimov
_______________________________________________
dali-dev mailing list
dali-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/dali-dev
_______________________________________________
dali-dev mailing list
dali-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/dali-dev
--
Paul Fullbright
Eclipse Java Persistence Tools (Dali) Development
Oracle
|