[hibernate-dev] hiberate-commons-annotations and locating annotations
Steve Ebersole
steve at hibernate.org
Wed Sep 4 15:44:40 EDT 2013
I am still a bit confused on how to apply the normalization to make sure
it happens in the proper order.
Let's look at:
@Entity
class Person {
...
@Embedded
@Convert( attributeName="city", converter=Converter2.class )
public Address homeAddress;
}
@Embeddable
class Address {
...
@Convert( converter=Converter1.class )
public String city;
}
So here, the Converter2 class ought to be the one applied to
"homeAddress.city" path.
Now granted there are a few different ways to skin this cat, but the
plan I had was to normalize these all on the root of the path. So here,
both of these conversions would get stored on
ClassPropertyHolder<Person> under the "homeAddress.city" path. When I
go to build the SimpleValue for Person.homeAddress.city, I'd ask the
CompositePropertyHolder for Person.homeAddress to resolve the explicit
(non-autoApply) conversion for its city attribute (the simple value).
The trouble I have though is applying the conversions in the proper
order. For example, here, I'd want to apply the conversions defined
directly on the Embeddable first (the Embeddable conversions should
always act as the baseline), then the conversions at its Embedded point
(via XML or annotations).
One idea was to hook into org.hibernate.cfg.PropertyHolder#addProperty
in terms of normalizing the paths. I am just not sure of the timing
between these PropertyHolder#addProperty (and how populated the passed
Property objects are at that point) and the calls to
SimpleValueBinder/PropertyBinder.
Interestingly, I still am not sure we have enough here to report an
error in cases like:
@Entity
@Convert( attributeName="homeAddress.city", converter=Converter3.class )
class Person {
...
@Embedded
@Convert( attributeName="city", converter=Converter2.class )
public Address homeAddress;
}
Unless we somehow kept "proximity info" or "location info" about the
conversion in PropertyHolder.
On Wed 04 Sep 2013 01:27:21 AM CDT, Emmanuel Bernard wrote:
>
> On Tue 2013-09-03 17:22, Steve Ebersole wrote:
>>
>> 2.a) It seems like there are times when
>> org.hibernate.cfg.AbstractPropertyHolder#parent would be useful for
>> what I need to do. But there appears to be times when this is null.
>> For entity mappings (ClassPropertyHolder) thats fine. But for the
>> others, that would be problematic. Going back to the
>> Person#homeAddress example, I'd really need the
>> ComponentPropertyHolder for Person#homeAddress to register the
>> converts with ClassPropertyHolder<Person> under the "homeAddress"
>> base key ("homeAddress.city" for example). Is there a time here
>> where AbstractPropertyHolder#parent would be null for
>> ComponentPropertyHolder/CollectionPropertyHolder?
>
>
> I looked around the code base and the only case I could find is for
> ClassPropertyHolder whose parent is indeed null.
>
>>
>> 2.b) Is this AbstractPropertyHolder#parent the best way you see to
>> handle path-based converts? Or do you see a better option?
>>
>
>
> Yes I still think it's the best aproach and frankly I don't quite see
> alternatives.
More information about the hibernate-dev
mailing list