You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Rick Curtis <cu...@gmail.com> on 2015/07/01 12:53:00 UTC

Re: chicken-egg problem with metadata and persistent fields

I'm just shooting in the dark here, but I wonder if you need to make
changes to the enhancer in addition to the metadatarepo..... then again its
quite early so I might be way off in left field.

On Tue, Jun 30, 2015 at 2:53 PM, Mark Struberg <st...@yahoo.de> wrote:

> Hi Rick!
>
> I’m trying to finally solve the long outstanding issue that our @Strategy
> and FieldStrategies configuration is pretty much broken. See
> https://issues.apache.org/jira/browse/OPENJPA-2341
> It is broken if the type you like to store is not Serializable. E.g.
> (taken from my current unit test):
>
>
> @Strategy("org.apache.openjpa.persistence.strategy.value.PrincipalValueStrategyHandler")
> private Principal user;
>
> This blows up because OpenJPA totally ignores this field (as it is not any
> of the spec defined types and the Strategy gets ignored). I was not able to
> get it working by adding @Basic (blows up complaining that the field is not
> Serializable), @Column (just ignored), @Persistent (complains about tons of
> other stuff).
>
> It ‚accidentially‘ works with Serializable classes because those get
> picked up as BASIC. Like joda and java8 LocalDate for example.
>
> But they are not really @Basic!
> If you take the sample above, then the representation of the instance in
> the entity has _nothing_ to do with the final representation in the
> database. That could e.g. simply store that info in a VARCHAR(20)
>
> I gonna attach my current wip to the JIRA.
>
> Not sure whether we should ty to cleanly sovle this or back up and just
> commit what I have now which at least works for Serializable fields.
>
> LieGrue,
> strub
>
>
> > Am 30.06.2015 um 21:22 schrieb Rick Curtis <cu...@gmail.com>:
> >
> > Any more context as to the problem you're running into/trying to solve?
> >
> > On Tue, Jun 30, 2015 at 11:31 AM, Mark Struberg <st...@yahoo.de>
> wrote:
> >
> >> Hi folks!
> >>
> >> I sense some chicken-egg proglem with FieldMapping and what field
> becomes
> >> a persistent column.
> >>
> >> The point is that only fields which have a valid FieldMapping will
> become
> >> a persistent column.
> >>
> >> Currently the main check - as far as I do understand so far - is in
> >> PersistenceMetaDataDefaults#getPersistenceStrategy.
> >> Only fields which have some specific mapping annotations
> >> (PersistenceMetaDataDefaults#_strats) or implement Serializable get
> >> automatically picked up. Other classes get totally ignored. Even if I
> >> explicitly have a @Strategy annotation on them or if I register global
> >> FieldStrategies.
> >>
> >> I cannot extend the _strats to @Strategy.class as
> >> PersistenceMetaDataDefaults is defined in openjpa-persistence but
> Strategy
> >> is only defined later in openjpa-persistence-jdbc.
> >>
> >> What we could possibly do is to extend _attrs with the @Column
> annotation
> >> class?
> >>
> >> Any other ideas?
> >>
> >> LieGrue,
> >> strub
> >
> >
> >
> >
> > --
> > *Rick Curtis*
>
>


-- 
*Rick Curtis*

Re: chicken-egg problem with metadata and persistent fields

Posted by Rick Curtis <cu...@gmail.com>.
> Do we really store entity Metas in a global static Map?
!ClassMetaData metas, but yes. In my opinion the PCRegistry is really
pretty gross, but I'm not sure of the butchering that would be involved in
designing it away.

> What if the same entity class gets used in different persistence units
but with different configuration?
I would guess that we are broken in this case... and I'm pretty certain
this isn't documented anywhere. We have a similar problem if you share
Entities across multiple persistence units and those units have different
openjpa.DetachState settings.

On Fri, Jul 3, 2015 at 1:21 AM, Mark Struberg <st...@yahoo.de> wrote:

> I have yet another thing which leaves me puzzled:
>
> I found that PCRegistry _might_ be a candidate to put the List of types
> which get handled via global FieldStrategies. It already stores the map of
> entity classes -> Meta information in _meta.
>
> But otoh all this (the existing code) looks somehow weird to me. Do we
> really store entity Metas in a global static Map? What if the same entity
> class gets used in different persistence units but with different
> configuration?
> In the end for my use case (FieldStrategies) it would not make sense to
> have them differently configured. But still one might use different
> configuration for serialization, etc. Is this up to random behaviour if the
> persistenceunits look different? Or do we simply rely on having the
> environment sanely separate those runtimes via ClassLoading tricks (forcing
> openjpa to use the app ClassLoader instead of the container ClassLoader)?
> Or did I get all this totally wrong?
>
> LieGrue,
> strub
>
>
> > Am 01.07.2015 um 16:04 schrieb Mark Struberg <st...@yahoo.de>:
> >
> > Yes, this is indeed one of the core classes involved.
> >
> > The problem is that the line 223
> > def = isDefaultPersistent(meta, member, name, ignoreTransient);
> >
> > returns false as PersistenceMetaDataDefaults:667
> >
> > PersistenceStrategy strat = getPersistenceStrategy(meta, null, member,
> ignoreTransient);
> >
> > doesn’t detect a strategy for this field as Principal is not
> Serializable. For LocalDate - which is Serializable - it works as this line
> returns PersistenceStrategy.BASIC.
> >
> > I think I gonna commit the basic fix which at least gets us all
> Serializable fields working. And then I’ll open another Jira to work on the
> non-Serializable parts.
> >
> > LieGrue,
> > strub
> >
> >> Am 01.07.2015 um 15:36 schrieb Rick Curtis <cu...@gmail.com>:
> >>
> >> Have you looked through org.apache.openjpa.meta.AbstractMetaDataDefaults
> >>
> <eclipse-javadoc:%E2%98%82=openjpa-kernel/src%5C/main%5C/java%3Corg.apache.openjpa.meta%7BAbstractMetaDataDefaults.java%E2%98%83AbstractMetaDataDefaults>.populateFromReflection(...)
> >> ?
> >>
> >> On Wed, Jul 1, 2015 at 8:04 AM, Mark Struberg <st...@yahoo.de>
> wrote:
> >>
> >>> Indeed the enhancer is involved in the game.
> >>> But I had hoped to _not_ need to change the enhancer itself. It just
> needs
> >>> to pickup the field as persistent.
> >>>
> >>> At the end what I like to achieve is that those fields are really
> handled
> >>> the same like PersistenceStrategy.BASIC.
> >>> With the only difference that a @Basic field currently needs to be
> >>> Serializable. This check is done pretty early - even before the
> >>> FieldStrategies get parsed. So we might be fine to fully remove this
> check
> >>> or at least somehow postpone it to a later stage and skip the check if
> we
> >>> know if a Strategy/ValueHandler is applied to this field. At least I
> have
> >>> no better idea at this moment ;)
> >>>
> >>> LieGrue,
> >>> strub
> >>>
> >>>> Am 01.07.2015 um 12:53 schrieb Rick Curtis <cu...@gmail.com>:
> >>>>
> >>>> I'm just shooting in the dark here, but I wonder if you need to make
> >>>> changes to the enhancer in addition to the metadatarepo..... then
> again
> >>> its
> >>>> quite early so I might be way off in left field.
> >>>>
> >>>> On Tue, Jun 30, 2015 at 2:53 PM, Mark Struberg <st...@yahoo.de>
> >>> wrote:
> >>>>
> >>>>> Hi Rick!
> >>>>>
> >>>>> I’m trying to finally solve the long outstanding issue that our
> >>> @Strategy
> >>>>> and FieldStrategies configuration is pretty much broken. See
> >>>>> https://issues.apache.org/jira/browse/OPENJPA-2341
> >>>>> It is broken if the type you like to store is not Serializable. E.g.
> >>>>> (taken from my current unit test):
> >>>>>
> >>>>>
> >>>>>
> >>>
> @Strategy("org.apache.openjpa.persistence.strategy.value.PrincipalValueStrategyHandler")
> >>>>> private Principal user;
> >>>>>
> >>>>> This blows up because OpenJPA totally ignores this field (as it is
> not
> >>> any
> >>>>> of the spec defined types and the Strategy gets ignored). I was not
> >>> able to
> >>>>> get it working by adding @Basic (blows up complaining that the field
> is
> >>> not
> >>>>> Serializable), @Column (just ignored), @Persistent (complains about
> >>> tons of
> >>>>> other stuff).
> >>>>>
> >>>>> It ‚accidentially‘ works with Serializable classes because those get
> >>>>> picked up as BASIC. Like joda and java8 LocalDate for example.
> >>>>>
> >>>>> But they are not really @Basic!
> >>>>> If you take the sample above, then the representation of the
> instance in
> >>>>> the entity has _nothing_ to do with the final representation in the
> >>>>> database. That could e.g. simply store that info in a VARCHAR(20)
> >>>>>
> >>>>> I gonna attach my current wip to the JIRA.
> >>>>>
> >>>>> Not sure whether we should ty to cleanly sovle this or back up and
> just
> >>>>> commit what I have now which at least works for Serializable fields.
> >>>>>
> >>>>> LieGrue,
> >>>>> strub
> >>>>>
> >>>>>
> >>>>>> Am 30.06.2015 um 21:22 schrieb Rick Curtis <cu...@gmail.com>:
> >>>>>>
> >>>>>> Any more context as to the problem you're running into/trying to
> solve?
> >>>>>>
> >>>>>> On Tue, Jun 30, 2015 at 11:31 AM, Mark Struberg <st...@yahoo.de>
> >>>>> wrote:
> >>>>>>
> >>>>>>> Hi folks!
> >>>>>>>
> >>>>>>> I sense some chicken-egg proglem with FieldMapping and what field
> >>>>> becomes
> >>>>>>> a persistent column.
> >>>>>>>
> >>>>>>> The point is that only fields which have a valid FieldMapping will
> >>>>> become
> >>>>>>> a persistent column.
> >>>>>>>
> >>>>>>> Currently the main check - as far as I do understand so far - is in
> >>>>>>> PersistenceMetaDataDefaults#getPersistenceStrategy.
> >>>>>>> Only fields which have some specific mapping annotations
> >>>>>>> (PersistenceMetaDataDefaults#_strats) or implement Serializable get
> >>>>>>> automatically picked up. Other classes get totally ignored. Even
> if I
> >>>>>>> explicitly have a @Strategy annotation on them or if I register
> global
> >>>>>>> FieldStrategies.
> >>>>>>>
> >>>>>>> I cannot extend the _strats to @Strategy.class as
> >>>>>>> PersistenceMetaDataDefaults is defined in openjpa-persistence but
> >>>>> Strategy
> >>>>>>> is only defined later in openjpa-persistence-jdbc.
> >>>>>>>
> >>>>>>> What we could possibly do is to extend _attrs with the @Column
> >>>>> annotation
> >>>>>>> class?
> >>>>>>>
> >>>>>>> Any other ideas?
> >>>>>>>
> >>>>>>> LieGrue,
> >>>>>>> strub
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> --
> >>>>>> *Rick Curtis*
> >>>>>
> >>>>>
> >>>>
> >>>>
> >>>> --
> >>>> *Rick Curtis*
> >>>
> >>>
> >>
> >>
> >> --
> >> *Rick Curtis*
> >
>
>


-- 
*Rick Curtis*

Re: chicken-egg problem with metadata and persistent fields

Posted by Mark Struberg <st...@yahoo.de>.
I have yet another thing which leaves me puzzled:

I found that PCRegistry _might_ be a candidate to put the List of types which get handled via global FieldStrategies. It already stores the map of entity classes -> Meta information in _meta.

But otoh all this (the existing code) looks somehow weird to me. Do we really store entity Metas in a global static Map? What if the same entity class gets used in different persistence units but with different configuration?
In the end for my use case (FieldStrategies) it would not make sense to have them differently configured. But still one might use different configuration for serialization, etc. Is this up to random behaviour if the persistenceunits look different? Or do we simply rely on having the environment sanely separate those runtimes via ClassLoading tricks (forcing openjpa to use the app ClassLoader instead of the container ClassLoader)?
Or did I get all this totally wrong?

LieGrue,
strub


> Am 01.07.2015 um 16:04 schrieb Mark Struberg <st...@yahoo.de>:
> 
> Yes, this is indeed one of the core classes involved.
> 
> The problem is that the line 223
> def = isDefaultPersistent(meta, member, name, ignoreTransient);
> 
> returns false as PersistenceMetaDataDefaults:667
> 
> PersistenceStrategy strat = getPersistenceStrategy(meta, null, member, ignoreTransient);
> 
> doesn’t detect a strategy for this field as Principal is not Serializable. For LocalDate - which is Serializable - it works as this line returns PersistenceStrategy.BASIC. 
> 
> I think I gonna commit the basic fix which at least gets us all Serializable fields working. And then I’ll open another Jira to work on the non-Serializable parts.
> 
> LieGrue,
> strub
> 
>> Am 01.07.2015 um 15:36 schrieb Rick Curtis <cu...@gmail.com>:
>> 
>> Have you looked through org.apache.openjpa.meta.AbstractMetaDataDefaults
>> <eclipse-javadoc:%E2%98%82=openjpa-kernel/src%5C/main%5C/java%3Corg.apache.openjpa.meta%7BAbstractMetaDataDefaults.java%E2%98%83AbstractMetaDataDefaults>.populateFromReflection(...)
>> ?
>> 
>> On Wed, Jul 1, 2015 at 8:04 AM, Mark Struberg <st...@yahoo.de> wrote:
>> 
>>> Indeed the enhancer is involved in the game.
>>> But I had hoped to _not_ need to change the enhancer itself. It just needs
>>> to pickup the field as persistent.
>>> 
>>> At the end what I like to achieve is that those fields are really handled
>>> the same like PersistenceStrategy.BASIC.
>>> With the only difference that a @Basic field currently needs to be
>>> Serializable. This check is done pretty early - even before the
>>> FieldStrategies get parsed. So we might be fine to fully remove this check
>>> or at least somehow postpone it to a later stage and skip the check if we
>>> know if a Strategy/ValueHandler is applied to this field. At least I have
>>> no better idea at this moment ;)
>>> 
>>> LieGrue,
>>> strub
>>> 
>>>> Am 01.07.2015 um 12:53 schrieb Rick Curtis <cu...@gmail.com>:
>>>> 
>>>> I'm just shooting in the dark here, but I wonder if you need to make
>>>> changes to the enhancer in addition to the metadatarepo..... then again
>>> its
>>>> quite early so I might be way off in left field.
>>>> 
>>>> On Tue, Jun 30, 2015 at 2:53 PM, Mark Struberg <st...@yahoo.de>
>>> wrote:
>>>> 
>>>>> Hi Rick!
>>>>> 
>>>>> I’m trying to finally solve the long outstanding issue that our
>>> @Strategy
>>>>> and FieldStrategies configuration is pretty much broken. See
>>>>> https://issues.apache.org/jira/browse/OPENJPA-2341
>>>>> It is broken if the type you like to store is not Serializable. E.g.
>>>>> (taken from my current unit test):
>>>>> 
>>>>> 
>>>>> 
>>> @Strategy("org.apache.openjpa.persistence.strategy.value.PrincipalValueStrategyHandler")
>>>>> private Principal user;
>>>>> 
>>>>> This blows up because OpenJPA totally ignores this field (as it is not
>>> any
>>>>> of the spec defined types and the Strategy gets ignored). I was not
>>> able to
>>>>> get it working by adding @Basic (blows up complaining that the field is
>>> not
>>>>> Serializable), @Column (just ignored), @Persistent (complains about
>>> tons of
>>>>> other stuff).
>>>>> 
>>>>> It ‚accidentially‘ works with Serializable classes because those get
>>>>> picked up as BASIC. Like joda and java8 LocalDate for example.
>>>>> 
>>>>> But they are not really @Basic!
>>>>> If you take the sample above, then the representation of the instance in
>>>>> the entity has _nothing_ to do with the final representation in the
>>>>> database. That could e.g. simply store that info in a VARCHAR(20)
>>>>> 
>>>>> I gonna attach my current wip to the JIRA.
>>>>> 
>>>>> Not sure whether we should ty to cleanly sovle this or back up and just
>>>>> commit what I have now which at least works for Serializable fields.
>>>>> 
>>>>> LieGrue,
>>>>> strub
>>>>> 
>>>>> 
>>>>>> Am 30.06.2015 um 21:22 schrieb Rick Curtis <cu...@gmail.com>:
>>>>>> 
>>>>>> Any more context as to the problem you're running into/trying to solve?
>>>>>> 
>>>>>> On Tue, Jun 30, 2015 at 11:31 AM, Mark Struberg <st...@yahoo.de>
>>>>> wrote:
>>>>>> 
>>>>>>> Hi folks!
>>>>>>> 
>>>>>>> I sense some chicken-egg proglem with FieldMapping and what field
>>>>> becomes
>>>>>>> a persistent column.
>>>>>>> 
>>>>>>> The point is that only fields which have a valid FieldMapping will
>>>>> become
>>>>>>> a persistent column.
>>>>>>> 
>>>>>>> Currently the main check - as far as I do understand so far - is in
>>>>>>> PersistenceMetaDataDefaults#getPersistenceStrategy.
>>>>>>> Only fields which have some specific mapping annotations
>>>>>>> (PersistenceMetaDataDefaults#_strats) or implement Serializable get
>>>>>>> automatically picked up. Other classes get totally ignored. Even if I
>>>>>>> explicitly have a @Strategy annotation on them or if I register global
>>>>>>> FieldStrategies.
>>>>>>> 
>>>>>>> I cannot extend the _strats to @Strategy.class as
>>>>>>> PersistenceMetaDataDefaults is defined in openjpa-persistence but
>>>>> Strategy
>>>>>>> is only defined later in openjpa-persistence-jdbc.
>>>>>>> 
>>>>>>> What we could possibly do is to extend _attrs with the @Column
>>>>> annotation
>>>>>>> class?
>>>>>>> 
>>>>>>> Any other ideas?
>>>>>>> 
>>>>>>> LieGrue,
>>>>>>> strub
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> --
>>>>>> *Rick Curtis*
>>>>> 
>>>>> 
>>>> 
>>>> 
>>>> --
>>>> *Rick Curtis*
>>> 
>>> 
>> 
>> 
>> -- 
>> *Rick Curtis*
> 


Re: chicken-egg problem with metadata and persistent fields

Posted by Mark Struberg <st...@yahoo.de>.
Yes, this is indeed one of the core classes involved.

The problem is that the line 223
def = isDefaultPersistent(meta, member, name, ignoreTransient);

returns false as PersistenceMetaDataDefaults:667

PersistenceStrategy strat = getPersistenceStrategy(meta, null, member, ignoreTransient);

doesn’t detect a strategy for this field as Principal is not Serializable. For LocalDate - which is Serializable - it works as this line returns PersistenceStrategy.BASIC. 

I think I gonna commit the basic fix which at least gets us all Serializable fields working. And then I’ll open another Jira to work on the non-Serializable parts.

LieGrue,
strub

> Am 01.07.2015 um 15:36 schrieb Rick Curtis <cu...@gmail.com>:
> 
> Have you looked through org.apache.openjpa.meta.AbstractMetaDataDefaults
> <eclipse-javadoc:%E2%98%82=openjpa-kernel/src%5C/main%5C/java%3Corg.apache.openjpa.meta%7BAbstractMetaDataDefaults.java%E2%98%83AbstractMetaDataDefaults>.populateFromReflection(...)
> ?
> 
> On Wed, Jul 1, 2015 at 8:04 AM, Mark Struberg <st...@yahoo.de> wrote:
> 
>> Indeed the enhancer is involved in the game.
>> But I had hoped to _not_ need to change the enhancer itself. It just needs
>> to pickup the field as persistent.
>> 
>> At the end what I like to achieve is that those fields are really handled
>> the same like PersistenceStrategy.BASIC.
>> With the only difference that a @Basic field currently needs to be
>> Serializable. This check is done pretty early - even before the
>> FieldStrategies get parsed. So we might be fine to fully remove this check
>> or at least somehow postpone it to a later stage and skip the check if we
>> know if a Strategy/ValueHandler is applied to this field. At least I have
>> no better idea at this moment ;)
>> 
>> LieGrue,
>> strub
>> 
>>> Am 01.07.2015 um 12:53 schrieb Rick Curtis <cu...@gmail.com>:
>>> 
>>> I'm just shooting in the dark here, but I wonder if you need to make
>>> changes to the enhancer in addition to the metadatarepo..... then again
>> its
>>> quite early so I might be way off in left field.
>>> 
>>> On Tue, Jun 30, 2015 at 2:53 PM, Mark Struberg <st...@yahoo.de>
>> wrote:
>>> 
>>>> Hi Rick!
>>>> 
>>>> I’m trying to finally solve the long outstanding issue that our
>> @Strategy
>>>> and FieldStrategies configuration is pretty much broken. See
>>>> https://issues.apache.org/jira/browse/OPENJPA-2341
>>>> It is broken if the type you like to store is not Serializable. E.g.
>>>> (taken from my current unit test):
>>>> 
>>>> 
>>>> 
>> @Strategy("org.apache.openjpa.persistence.strategy.value.PrincipalValueStrategyHandler")
>>>> private Principal user;
>>>> 
>>>> This blows up because OpenJPA totally ignores this field (as it is not
>> any
>>>> of the spec defined types and the Strategy gets ignored). I was not
>> able to
>>>> get it working by adding @Basic (blows up complaining that the field is
>> not
>>>> Serializable), @Column (just ignored), @Persistent (complains about
>> tons of
>>>> other stuff).
>>>> 
>>>> It ‚accidentially‘ works with Serializable classes because those get
>>>> picked up as BASIC. Like joda and java8 LocalDate for example.
>>>> 
>>>> But they are not really @Basic!
>>>> If you take the sample above, then the representation of the instance in
>>>> the entity has _nothing_ to do with the final representation in the
>>>> database. That could e.g. simply store that info in a VARCHAR(20)
>>>> 
>>>> I gonna attach my current wip to the JIRA.
>>>> 
>>>> Not sure whether we should ty to cleanly sovle this or back up and just
>>>> commit what I have now which at least works for Serializable fields.
>>>> 
>>>> LieGrue,
>>>> strub
>>>> 
>>>> 
>>>>> Am 30.06.2015 um 21:22 schrieb Rick Curtis <cu...@gmail.com>:
>>>>> 
>>>>> Any more context as to the problem you're running into/trying to solve?
>>>>> 
>>>>> On Tue, Jun 30, 2015 at 11:31 AM, Mark Struberg <st...@yahoo.de>
>>>> wrote:
>>>>> 
>>>>>> Hi folks!
>>>>>> 
>>>>>> I sense some chicken-egg proglem with FieldMapping and what field
>>>> becomes
>>>>>> a persistent column.
>>>>>> 
>>>>>> The point is that only fields which have a valid FieldMapping will
>>>> become
>>>>>> a persistent column.
>>>>>> 
>>>>>> Currently the main check - as far as I do understand so far - is in
>>>>>> PersistenceMetaDataDefaults#getPersistenceStrategy.
>>>>>> Only fields which have some specific mapping annotations
>>>>>> (PersistenceMetaDataDefaults#_strats) or implement Serializable get
>>>>>> automatically picked up. Other classes get totally ignored. Even if I
>>>>>> explicitly have a @Strategy annotation on them or if I register global
>>>>>> FieldStrategies.
>>>>>> 
>>>>>> I cannot extend the _strats to @Strategy.class as
>>>>>> PersistenceMetaDataDefaults is defined in openjpa-persistence but
>>>> Strategy
>>>>>> is only defined later in openjpa-persistence-jdbc.
>>>>>> 
>>>>>> What we could possibly do is to extend _attrs with the @Column
>>>> annotation
>>>>>> class?
>>>>>> 
>>>>>> Any other ideas?
>>>>>> 
>>>>>> LieGrue,
>>>>>> strub
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> --
>>>>> *Rick Curtis*
>>>> 
>>>> 
>>> 
>>> 
>>> --
>>> *Rick Curtis*
>> 
>> 
> 
> 
> -- 
> *Rick Curtis*


Re: chicken-egg problem with metadata and persistent fields

Posted by Rick Curtis <cu...@gmail.com>.
Have you looked through org.apache.openjpa.meta.AbstractMetaDataDefaults
<eclipse-javadoc:%E2%98%82=openjpa-kernel/src%5C/main%5C/java%3Corg.apache.openjpa.meta%7BAbstractMetaDataDefaults.java%E2%98%83AbstractMetaDataDefaults>.populateFromReflection(...)
?

On Wed, Jul 1, 2015 at 8:04 AM, Mark Struberg <st...@yahoo.de> wrote:

> Indeed the enhancer is involved in the game.
> But I had hoped to _not_ need to change the enhancer itself. It just needs
> to pickup the field as persistent.
>
> At the end what I like to achieve is that those fields are really handled
> the same like PersistenceStrategy.BASIC.
> With the only difference that a @Basic field currently needs to be
> Serializable. This check is done pretty early - even before the
> FieldStrategies get parsed. So we might be fine to fully remove this check
> or at least somehow postpone it to a later stage and skip the check if we
> know if a Strategy/ValueHandler is applied to this field. At least I have
> no better idea at this moment ;)
>
> LieGrue,
> strub
>
> > Am 01.07.2015 um 12:53 schrieb Rick Curtis <cu...@gmail.com>:
> >
> > I'm just shooting in the dark here, but I wonder if you need to make
> > changes to the enhancer in addition to the metadatarepo..... then again
> its
> > quite early so I might be way off in left field.
> >
> > On Tue, Jun 30, 2015 at 2:53 PM, Mark Struberg <st...@yahoo.de>
> wrote:
> >
> >> Hi Rick!
> >>
> >> I’m trying to finally solve the long outstanding issue that our
> @Strategy
> >> and FieldStrategies configuration is pretty much broken. See
> >> https://issues.apache.org/jira/browse/OPENJPA-2341
> >> It is broken if the type you like to store is not Serializable. E.g.
> >> (taken from my current unit test):
> >>
> >>
> >>
> @Strategy("org.apache.openjpa.persistence.strategy.value.PrincipalValueStrategyHandler")
> >> private Principal user;
> >>
> >> This blows up because OpenJPA totally ignores this field (as it is not
> any
> >> of the spec defined types and the Strategy gets ignored). I was not
> able to
> >> get it working by adding @Basic (blows up complaining that the field is
> not
> >> Serializable), @Column (just ignored), @Persistent (complains about
> tons of
> >> other stuff).
> >>
> >> It ‚accidentially‘ works with Serializable classes because those get
> >> picked up as BASIC. Like joda and java8 LocalDate for example.
> >>
> >> But they are not really @Basic!
> >> If you take the sample above, then the representation of the instance in
> >> the entity has _nothing_ to do with the final representation in the
> >> database. That could e.g. simply store that info in a VARCHAR(20)
> >>
> >> I gonna attach my current wip to the JIRA.
> >>
> >> Not sure whether we should ty to cleanly sovle this or back up and just
> >> commit what I have now which at least works for Serializable fields.
> >>
> >> LieGrue,
> >> strub
> >>
> >>
> >>> Am 30.06.2015 um 21:22 schrieb Rick Curtis <cu...@gmail.com>:
> >>>
> >>> Any more context as to the problem you're running into/trying to solve?
> >>>
> >>> On Tue, Jun 30, 2015 at 11:31 AM, Mark Struberg <st...@yahoo.de>
> >> wrote:
> >>>
> >>>> Hi folks!
> >>>>
> >>>> I sense some chicken-egg proglem with FieldMapping and what field
> >> becomes
> >>>> a persistent column.
> >>>>
> >>>> The point is that only fields which have a valid FieldMapping will
> >> become
> >>>> a persistent column.
> >>>>
> >>>> Currently the main check - as far as I do understand so far - is in
> >>>> PersistenceMetaDataDefaults#getPersistenceStrategy.
> >>>> Only fields which have some specific mapping annotations
> >>>> (PersistenceMetaDataDefaults#_strats) or implement Serializable get
> >>>> automatically picked up. Other classes get totally ignored. Even if I
> >>>> explicitly have a @Strategy annotation on them or if I register global
> >>>> FieldStrategies.
> >>>>
> >>>> I cannot extend the _strats to @Strategy.class as
> >>>> PersistenceMetaDataDefaults is defined in openjpa-persistence but
> >> Strategy
> >>>> is only defined later in openjpa-persistence-jdbc.
> >>>>
> >>>> What we could possibly do is to extend _attrs with the @Column
> >> annotation
> >>>> class?
> >>>>
> >>>> Any other ideas?
> >>>>
> >>>> LieGrue,
> >>>> strub
> >>>
> >>>
> >>>
> >>>
> >>> --
> >>> *Rick Curtis*
> >>
> >>
> >
> >
> > --
> > *Rick Curtis*
>
>


-- 
*Rick Curtis*

Re: chicken-egg problem with metadata and persistent fields

Posted by Mark Struberg <st...@yahoo.de>.
Indeed the enhancer is involved in the game.
But I had hoped to _not_ need to change the enhancer itself. It just needs to pickup the field as persistent.

At the end what I like to achieve is that those fields are really handled the same like PersistenceStrategy.BASIC.
With the only difference that a @Basic field currently needs to be Serializable. This check is done pretty early - even before the FieldStrategies get parsed. So we might be fine to fully remove this check or at least somehow postpone it to a later stage and skip the check if we know if a Strategy/ValueHandler is applied to this field. At least I have no better idea at this moment ;)

LieGrue,
strub

> Am 01.07.2015 um 12:53 schrieb Rick Curtis <cu...@gmail.com>:
> 
> I'm just shooting in the dark here, but I wonder if you need to make
> changes to the enhancer in addition to the metadatarepo..... then again its
> quite early so I might be way off in left field.
> 
> On Tue, Jun 30, 2015 at 2:53 PM, Mark Struberg <st...@yahoo.de> wrote:
> 
>> Hi Rick!
>> 
>> I’m trying to finally solve the long outstanding issue that our @Strategy
>> and FieldStrategies configuration is pretty much broken. See
>> https://issues.apache.org/jira/browse/OPENJPA-2341
>> It is broken if the type you like to store is not Serializable. E.g.
>> (taken from my current unit test):
>> 
>> 
>> @Strategy("org.apache.openjpa.persistence.strategy.value.PrincipalValueStrategyHandler")
>> private Principal user;
>> 
>> This blows up because OpenJPA totally ignores this field (as it is not any
>> of the spec defined types and the Strategy gets ignored). I was not able to
>> get it working by adding @Basic (blows up complaining that the field is not
>> Serializable), @Column (just ignored), @Persistent (complains about tons of
>> other stuff).
>> 
>> It ‚accidentially‘ works with Serializable classes because those get
>> picked up as BASIC. Like joda and java8 LocalDate for example.
>> 
>> But they are not really @Basic!
>> If you take the sample above, then the representation of the instance in
>> the entity has _nothing_ to do with the final representation in the
>> database. That could e.g. simply store that info in a VARCHAR(20)
>> 
>> I gonna attach my current wip to the JIRA.
>> 
>> Not sure whether we should ty to cleanly sovle this or back up and just
>> commit what I have now which at least works for Serializable fields.
>> 
>> LieGrue,
>> strub
>> 
>> 
>>> Am 30.06.2015 um 21:22 schrieb Rick Curtis <cu...@gmail.com>:
>>> 
>>> Any more context as to the problem you're running into/trying to solve?
>>> 
>>> On Tue, Jun 30, 2015 at 11:31 AM, Mark Struberg <st...@yahoo.de>
>> wrote:
>>> 
>>>> Hi folks!
>>>> 
>>>> I sense some chicken-egg proglem with FieldMapping and what field
>> becomes
>>>> a persistent column.
>>>> 
>>>> The point is that only fields which have a valid FieldMapping will
>> become
>>>> a persistent column.
>>>> 
>>>> Currently the main check - as far as I do understand so far - is in
>>>> PersistenceMetaDataDefaults#getPersistenceStrategy.
>>>> Only fields which have some specific mapping annotations
>>>> (PersistenceMetaDataDefaults#_strats) or implement Serializable get
>>>> automatically picked up. Other classes get totally ignored. Even if I
>>>> explicitly have a @Strategy annotation on them or if I register global
>>>> FieldStrategies.
>>>> 
>>>> I cannot extend the _strats to @Strategy.class as
>>>> PersistenceMetaDataDefaults is defined in openjpa-persistence but
>> Strategy
>>>> is only defined later in openjpa-persistence-jdbc.
>>>> 
>>>> What we could possibly do is to extend _attrs with the @Column
>> annotation
>>>> class?
>>>> 
>>>> Any other ideas?
>>>> 
>>>> LieGrue,
>>>> strub
>>> 
>>> 
>>> 
>>> 
>>> --
>>> *Rick Curtis*
>> 
>> 
> 
> 
> -- 
> *Rick Curtis*