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

@Reference(lazy = true) still loading all references #91

Open
seePatCode opened this issue Jul 3, 2012 · 11 comments
Open

@Reference(lazy = true) still loading all references #91

seePatCode opened this issue Jul 3, 2012 · 11 comments
Labels

Comments

@seePatCode
Copy link

I have the following User class referenced members:

@Entity
public class User extends Model 
{
    @Indexed @Reference(lazy = true) public Organization organization;
    @Reference(lazy = true)  public List<Team> coachedTeams = new ArrayList<Team>();
    @Reference(lazy = true) @Lazy public List<Notification> userNotifications = new ArrayList<Notification>();

When I simply lookup the user by email it then queries for the organization and all of the organization's @references (which are lazy as well). Thank you in advance for any help and please let me know if there is any further code you will need.

@greenlaw110
Copy link
Collaborator

can you follow this thread to verify it?
https://groups.google.com/forum/?fromgroups#!topic/morphia/d_51noQiPoo

On Wed, Jul 4, 2012 at 7:09 AM, Patrick Cullen <
reply@reply.github.com

wrote:

I have the following User class referenced members:

@Entity
public class User extends Model
{
    @Indexed @Reference(lazy = true) public Organization organization;
    @Reference(lazy = true)  public List<Team> coachedTeams = new
ArrayList<Team>();
    @Reference(lazy = true) @Lazy public List<Notification>
userNotifications = new ArrayList<Notification>();

When I simply lookup the user by email it then queries for the
organization and all of the organization's @references (which are lazy as
well). Thank you in advance for any help and please let me know if there is
any further code you will need.


Reply to this email directly or view it on GitHub:
#91

@seePatCode
Copy link
Author

Yes, I already did. I set breakpoints around the following line:

user = User.find("byEmail", Security.connected()).first();

The result was that all references were run.

@seePatCode
Copy link
Author

Pardon my ignorance but there isn't a full source I could step through to help investigate, is there? I'm not sure of the contents of play-morphia.jar.

@greenlaw110
Copy link
Collaborator

the source you want to refer is morphia, not play-morphia. go
http://code.google.com/p/morphia/ for the source

On Wed, Jul 4, 2012 at 7:53 AM, Patrick Cullen <
reply@reply.github.com

wrote:

Pardon my ignorance but there isn't a full source I could step through to
help investigate, is there? I'm not sure of the contents of
play-morphia.jar.


Reply to this email directly or view it on GitHub:
#91 (comment)

@seePatCode
Copy link
Author

I found that LazyFeatureDependencies is not being fulfilled once I traced the code which is causing it to ignore all lazy requests. I hope this helps.

@seePatCode
Copy link
Author

Also, just to elaborate on that above post, it looks as though the version of morphia that play-morphia is using is from April, 2011. From what I can gather this version of morphia has the hooks for lazy references but not the required dependencies. Here is the actual dependency check method:

public static boolean testDependencyFullFilled() {
        if (fullFilled != null)
            return fullFilled;
        try {
            fullFilled = Class.forName("net.sf.cglib.proxy.Enhancer") != null
                    && Class.forName("com.thoughtworks.proxy.toys.hotswap.HotSwapping") != null;
        } catch (ClassNotFoundException e) {
            fullFilled = false;
        }
        return fullFilled;
    }

@seePatCode
Copy link
Author

One last note, I decided to see what would happen if I just added the missing proxytoys,jar and the whole thing blows up with :
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message t
ransform method call failed at ../../../src/share/instrument/JPLISAgent.c line: 8
06
~ ...

-Newer versions of morphia have lazy references working, would it be possible to update the version of morphia in the module?

@seePatCode
Copy link
Author

I took a quick swing at this today and tried adding the latest from morphia but that didn't seem to help (snapshot 99.1). I think it may be a conflict issue since play also uses CGLIB (but without the dependencies). I tried adding the dependencies found from this list: http://cglib.sourceforge.net/dependencies.html. I won't be able to commit any more time to this in the near future so I am reworking a bunch of code to use ObjectIds instead of @reference. You may want to warn that (lazy=true) does not work since play-morphia's documentation alludes to the option of using it. I wouldn't want anyone to get as far down the rabbit hole as I did...

@anandbn
Copy link

anandbn commented Sep 1, 2013

Adding the below to pom.xml seems to do the trick for me:

        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib-nodep</artifactId>
            <version>[2.1_3,3.0)</version>
            <type>jar</type>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.thoughtworks.proxytoys</groupId>
            <artifactId>proxytoys</artifactId>
            <version>1.0</version>
            <type>jar</type>
            <optional>true</optional>
        </dependency>

which is slightly different from the project page's dependencies. Might we worth updating the dependencies.html to reflect it correctly.

@yepelinux
Copy link

anandbn, it didnt work to me.
Even though i used your library versions, all references are fetched (yes, not anymore system message like no dependecy found)

This is my java method:

public static void companies(String id) {

    System.out.println("Method start:");

    Company comp = Company.findById(id);
    if(comp !=null){
        System.out.println("rendering!");
        renderJSON(comp.name);
    }

}

Method start:
16:56:50,130 TRACE ~ MorphiaPlugin-1.4.0> Running query(Company) : { "_id" : { "$oid" : "50b2b94efff7782873fd0306"}}, fields:null,off:0,limit:1
16:56:50,130 TRACE ~ MorphiaPlugin-1.4.0> Getting cursor(Company) for query:{ "_id" : { "$oid" : "50b2b94efff7782873fd0306"}}
16:56:50,315 DEBUG ~ MorphiaPlugin-1.4.0> Calling interceptor method PreLoad on play.modules.morphia.MorphiaPlugin$1@5d8e95d9
16:56:50,316 TRACE ~ MorphiaPlugin-1.4.0> Running query(Account) : { "_id" : { "$oid" : "50b2b94efff7782873fd0307"}}, fields:{ "_id" : true},off:0,limit:-1
16:56:50,316 TRACE ~ MorphiaPlugin-1.4.0> Getting cursor(Account) for query:{ "_id" : { "$oid" : "50b2b94efff7782873fd0307"}}
16:56:50,546 TRACE ~ MorphiaPlugin-1.4.0> Running query(Campaign) : { "_id" : { "$in" : [ { "$oid" : "50b2b94ffff7782873fd0308"}]}}, fields:{ "_id" : true},off:0,limit:-1
16:56:50,546 TRACE ~ MorphiaPlugin-1.4.0> Getting cursor(Campaign) for query:{ "_id" : { "$in" : [ { "$oid" : "50b2b94ffff7782873fd0308"}]}}
16:56:50,730 DEBUG ~ MorphiaPlugin-1.4.0> Calling interceptor method PostLoad on play.modules.morphia.MorphiaPlugin$1@5d8e95d9
rendering!

So, even i only render comp.name both Company references (Account and Campaign) are fetched.

Any ideas?

@AddoSolutions
Copy link

Looks like this is an issue with Morphia itself:

https://groups.google.com/forum/#!topic/morphia/OEQtZLII8tI

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

5 participants