jackson-datatype-hibernate icon indicating copy to clipboard operation
jackson-datatype-hibernate copied to clipboard

EAGER collections still become PersistentCollections and are mapped as persistent

Open BenDol opened this issue 6 years ago • 7 comments

There should be an option to assume that all ManyToX and OneToX annotation markers are lazy to avoid the issue where there are times an EAGER collection will be a PersistentCollection.

For example, like so:

protected boolean usesLazyLoading(BeanProperty property) {
    if (property != null) {
        boolean assumeLazy = Feature.ASSUME_ANY_MARKER_IS_LAZY.enabledIn(_features)
        // As per [Issue#36]
        ElementCollection ec = property.getAnnotation(ElementCollection.class);
        if (ec != null) {
            return assumeLazy || (ec.fetch() == FetchType.LAZY);
        }
        OneToMany ann1 = property.getAnnotation(OneToMany.class);
        if (ann1 != null) {
            return assumeLazy || (ann1.fetch() == FetchType.LAZY);
        }
        OneToOne ann2 = property.getAnnotation(OneToOne.class);
        if (ann2 != null) {
            return assumeLazy || (ann2.fetch() == FetchType.LAZY);
        }
        ManyToOne ann3 = property.getAnnotation(ManyToOne.class);
        if (ann3 != null) {
            return assumeLazy || (ann3.fetch() == FetchType.LAZY);
        }
        ManyToMany ann4 = property.getAnnotation(ManyToMany.class);
        if (ann4 != null) {
            return assumeLazy || (ann4.fetch() == FetchType.LAZY);
        }
        // As per [Issue#53]
        return !Feature.REQUIRE_EXPLICIT_LAZY_LOADING_MARKER.enabledIn(_features);
    }
    return false;
}

BenDol avatar Sep 19 '18 13:09 BenDol

To clarify the issue I'm having, the code that replaces the persistent collection type information with a regular collection, requires that the property pass the usesLazyLoading check and in turn the type never changes for me with my EAGER collection. So either we check the types separate to the serialization write or we just assume that all are lazy.

BenDol avatar Sep 20 '18 02:09 BenDol

is there any progress on this issue?

BenDol avatar Jan 08 '19 22:01 BenDol

@BenDol if someone was working on this, there should be updates here, so I don't think there is or will be update unless someone has an itch. Unfortunately Hibernate module has no maintainer at this point.

cowtowncoder avatar Jan 08 '19 22:01 cowtowncoder

Why nobody fix it

kamtorocks avatar Feb 26 '19 07:02 kamtorocks

@leenin you volunteering?

cowtowncoder avatar Feb 28 '19 07:02 cowtowncoder

@cowtowncoder I was thinking about picking this up because we could really use ReplacePersistentCollections to work. I was wondering if you agree that this just needs to be covered by the REPLACE_PERSISTENT_COLLECTION feature? I don't see a reason to serialize the Persistent Collection to JSON, even if it was marked as an EAGER fetch when the above feature is enabled.

jackoneall avatar Jul 09 '21 17:07 jackoneall

@jackoneall I do not know Hibernate well enough to say either way; but typically when changing behavior it makes sense to add a configuration option, and making it default to old behavior (but allow opt-in for new variation).

But whether a new configuration option is added or not, this change should go in 2.13.0 (and not a patch release) -- master is for 2.13.

If you do have time to do a PR, timing would be good as I am about to release the first (and possibly only) RC for 2.13.0. So there is time to get this change in, and available relatively quickly.

cowtowncoder avatar Jul 09 '21 18:07 cowtowncoder