openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ashish paliwal <>
Subject Problem with @strategy
Date Sat, 30 May 2009 06:16:50 GMT

I had two entities, Person and Address with @OneToOne mapping. I wanted to
have a custom mapping for address data, so gave
@strategy(somepackage.MyStrategy) in getAddress() method in The
MyStrategy class was extending from RelationFieldStrategy class and I
overrode load() method. But, I saw that my strategy was never called. I
debugged and observed few things:
AnnotationPersistenceMappingParser was correctly parsing my @strategy
annotation in parseMemberMappingAnnotation() method and was executing case
Strat: setting strategy for ValueMappingInfo object. When execution came to
RuntimeStrategyInstaller.installStrategy() method, in the very first line it
was fetching strategy from FieldMappingInfo , not from ValueMappingInfo in
which AnnotationPersistenceMappingParser.parseMemberMappingAnnotation()
method had set the strategy. It ultimetely fetched the default strategy
When I changed the parseMemberMappingAnnotation()  method in case Strat: i
wrote fm.getMappingInfo().setStrategy(((Strategy) anno).value()) , which
basically stores strategy in FieldMappingInfo rather than in
ValueMappingInfo. Now everything ran smoothly and myStrategy was called.

I wanted to know where am I making mistake that my strategy is not being
called without making the change that I have made. I have gone through the
docs as well as some examples from the web, but to no help.

Offcourse there is another method of injecting my strategy, that of
extending PersistenceMappingDefaults and then overriding getStrategy()
method such that it calls myStrategy for Person.Address. Also entry of
overriden class has to be entered in persistence.xml. This I tried and
everything worked. But certainly, this is less user friendly for user than
to just write the @annotation tag over address field.

Any help is greatly appreciated.

thanks and regards

Ashish Paliwal
Mobile : 9305128367
IIT Kanpur

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message