Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy loading in interfaces #1217

Closed
JPDSousa opened this issue Dec 27, 2017 · 6 comments
Closed

Lazy loading in interfaces #1217

JPDSousa opened this issue Dec 27, 2017 · 6 comments
Labels
Milestone

Comments

@JPDSousa
Copy link

Hello, i've been using morphia on a java project, with a complex hierarchy (i.e. multiple interfaces, abstract classes, etc.). I've reach to a point where, in order to reduce the overhead of reading the entire structure of an entity, i decided to use the lazy loading features of Morphia. The problem arises when Morphia tries to lazy load a field that is stored as one of the interfaces used, for instance:

@Entity
public interface InterfaceA {
    ObjectId getId();
    InterfaceB getB();
}

@Entity
public class ClassA implements InterfaceA {
    @Id
    private ObjectId _id;
    @Reference(lazy = true)
    private InterfaceB b;
}

@Entity
public interface InterfaceB {
    ObjectId getId();
}

Considering that both InterfaceA and InterfaceBare entities stored in MongoDB, when i fetch an InterfaceA object from the database, b is wrapped in a proxy. However, upon invocation of any of the proxy's methods, Morphia will attempt to fetch the respective object with field validation turned on, as described in the source code. This creates an obvious problem, as validating fields over interface types makes no sense.

Is there any workaround or should this be considered a bug/enhancement?

As expressed in the CONTRIBUTING file:

  1. Morphia version: 1.3.2
  2. JDK version: 1.8
  3. MongoDB version: 3.4
  4. Any stacktraces generated by the failure: (i don't this is required, let me know if needed)
  5. If possible, a test case to recreate the behavior: (the example above is sufficient, but i can elaborate an example more realistic if it is needed).
@evanchooly
Copy link
Member

This is forever late, i know. I'm trying to get caught back up and prevent such delays in the future. Is this still an issue for you? Can you provide the error you were getting? I have a feeling I know the general themes of it but it would help me isolate the actual cause. Thanks.

@JPDSousa
Copy link
Author

Hey! Thanks for looking into this.

The truth is that I sort of abandoned the idea of using Morphia, as I couldn't find a workaround for this, and I really didn't want to give up of my data model (i.e turning interfaces into classes). I do not have a stack trace, and probably won't be able to provide you with one since my projects have then evolved, but I think the issue is quite reproducible.

Anyway, it would be really cool to have this fixed, and I'm glad to help as much as I can. 😄

@evanchooly
Copy link
Member

OK. Thanks for the update and sorry for the interminable delay. I'd stepped away for a while but I'm back now and trying to pick up the threads.

@JPDSousa
Copy link
Author

Good news then! 😄 Morphia is a great framework

@evanchooly evanchooly added this to the 1.5.0 milestone Mar 11, 2019
@evanchooly evanchooly added the bug label Mar 11, 2019
@evanchooly
Copy link
Member

fixed

@evanchooly
Copy link
Member

I still need to confirm maps/collections of lazy references...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants