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

Duplicated child RushObjects with circular relationships #29

Closed
PaulineBAUDOUIN opened this Issue Apr 28, 2015 · 21 comments

Comments

Projects
None yet
5 participants
@PaulineBAUDOUIN

PaulineBAUDOUIN commented Apr 28, 2015

Hi, it's me again, I have a problem which I can't manage to solve...
I have a first ActivityA which starts ActivityB when onClick on a button.
In my ActivityB, I want to create a new Projet (RushObject) so here is what I do to create it:

Projet toCreateProj = new Projet();
            toCreateProj.identifier = 1;
            toCreateProj.title = editText.getText().toString();
            toCreateProj.maquette = selectedMaq; 
            toCreateProj.user = utilisateur;
            toCreateProj.save();
            utilisateur.projets.add(toCreateProj); // a Utilisateur (RushObject) has many Projets
            utilisateur.save();
            System.out.println(toCreateProj.maquette.gabarits.size()); // returns 3
            dialog.cancel();
            finish();

selectedMaquette is a Maquette (RushObject) which I have by making a RushSearch. Same for utilisateur. My System.out returns 3 which is normal.
On finish(), I go back to my ActivityA. In the onResume() i do:

Projet toBeTested = new RushSearch().whereEqual("identifier", 1).findSingle(Projet.class); // I am sure it is the good project
        if(toBeTested != null){
            System.out.println("BIDON " + toBeTested.maquette.gabarits.size()); // returns 6
        }

But now, my System.out returns 6 but should still return 3. I really don't get why... Any idea ?
Thanks

@Stuart-campbell

This comment has been minimized.

Show comment
Hide comment
@Stuart-campbell

Stuart-campbell Apr 28, 2015

Owner

You might have multiple projects with identifier = 1 that you created while developing? So find single might not be returning the object you just created?

Owner

Stuart-campbell commented Apr 28, 2015

You might have multiple projects with identifier = 1 that you created while developing? So find single might not be returning the object you just created?

@PaulineBAUDOUIN

This comment has been minimized.

Show comment
Hide comment
@PaulineBAUDOUIN

PaulineBAUDOUIN Apr 28, 2015

In my whole application, I only create one Projet so it can only be this one I think. I am really sure this is the Projet I want !

PaulineBAUDOUIN commented Apr 28, 2015

In my whole application, I only create one Projet so it can only be this one I think. I am really sure this is the Projet I want !

@Stuart-campbell

This comment has been minimized.

Show comment
Hide comment
@Stuart-campbell

Stuart-campbell Apr 28, 2015

Owner

Try removing this line.

toCreateProj.save();

As saving utilisateur should save all the children.

Although wondering if something might be going wrong saving children that also have children.

Owner

Stuart-campbell commented Apr 28, 2015

Try removing this line.

toCreateProj.save();

As saving utilisateur should save all the children.

Although wondering if something might be going wrong saving children that also have children.

@PaulineBAUDOUIN

This comment has been minimized.

Show comment
Hide comment
@PaulineBAUDOUIN

PaulineBAUDOUIN Apr 28, 2015

That's also what I thought because in my application, there are RushObjects:

  • Maquette associated with one or many Utilisateurs and Projets.
  • Utilisateur associated with one or many Maquettes and Projets.
  • Projet associated with one Maquette and one Utilisateur.

So there is a triangle which might be the cause of the duplication.

PaulineBAUDOUIN commented Apr 28, 2015

That's also what I thought because in my application, there are RushObjects:

  • Maquette associated with one or many Utilisateurs and Projets.
  • Utilisateur associated with one or many Maquettes and Projets.
  • Projet associated with one Maquette and one Utilisateur.

So there is a triangle which might be the cause of the duplication.

@Stuart-campbell

This comment has been minimized.

Show comment
Hide comment
@Stuart-campbell

Stuart-campbell Apr 28, 2015

Owner

Does this look like your example.

ClassA extends RushObject {
    List<ClassB> classBs
    List<ClassC> classCs
 }

ClassB extends RushObject {
    List<ClassA> classAs;
    List<ClassC> classCs;
}

ClassC extends RushObject {
    ClassA classA;
    ClassB classB;
}

If it is ill try to reproduce. Might take a little time as not the most simple example.

Owner

Stuart-campbell commented Apr 28, 2015

Does this look like your example.

ClassA extends RushObject {
    List<ClassB> classBs
    List<ClassC> classCs
 }

ClassB extends RushObject {
    List<ClassA> classAs;
    List<ClassC> classCs;
}

ClassC extends RushObject {
    ClassA classA;
    ClassB classB;
}

If it is ill try to reproduce. Might take a little time as not the most simple example.

@PaulineBAUDOUIN

This comment has been minimized.

Show comment
Hide comment
@PaulineBAUDOUIN

PaulineBAUDOUIN Apr 28, 2015

Ok so I changes a little bit the structure of the database into a more simple one so here is the new one:

Gabarit extends RushObject{
}

Maquette extends RushObject{
    List<Gabarit> gabarits;
}

Utilisateur extends RushObject{
    List<Maquette> maquettes;
}

Projet extends RushObject{
    Maquette maquette;
    Utilisateur user;
}

So when I create a new Projet as I do in my first post, it duplicates all the items in the list gabarits of the Maquette class and I don't understand why...

PaulineBAUDOUIN commented Apr 28, 2015

Ok so I changes a little bit the structure of the database into a more simple one so here is the new one:

Gabarit extends RushObject{
}

Maquette extends RushObject{
    List<Gabarit> gabarits;
}

Utilisateur extends RushObject{
    List<Maquette> maquettes;
}

Projet extends RushObject{
    Maquette maquette;
    Utilisateur user;
}

So when I create a new Projet as I do in my first post, it duplicates all the items in the list gabarits of the Maquette class and I don't understand why...

@PaulineBAUDOUIN

This comment has been minimized.

Show comment
Hide comment
@PaulineBAUDOUIN

PaulineBAUDOUIN Apr 28, 2015

Here is what I do to save a Projet:

Projet toCreateProj = new Projet();
            toCreateProj.identifier = 1;//toCreateProj.getNewIdentifier();
            toCreateProj.title = editText.getText().toString();
            toCreateProj.maquette = selectedMaq;
            toCreateProj.user = utilisateur;

            Maquette m1 = new RushSearch().whereEqual("nom", selectedMaq.nom).findSingle(Maquette.class);
            System.out.println("size 1: " + m1.gabarits.size());

            toCreateProj.save();

            Maquette m2 = new RushSearch().whereEqual("nom", selectedMaq.nom).findSingle(Maquette.class);
            System.out.println("size 2: " + m2.gabarits.size());

So my first System.out displays 3 (normal) and the second one displays 6 because of duplication

PaulineBAUDOUIN commented Apr 28, 2015

Here is what I do to save a Projet:

Projet toCreateProj = new Projet();
            toCreateProj.identifier = 1;//toCreateProj.getNewIdentifier();
            toCreateProj.title = editText.getText().toString();
            toCreateProj.maquette = selectedMaq;
            toCreateProj.user = utilisateur;

            Maquette m1 = new RushSearch().whereEqual("nom", selectedMaq.nom).findSingle(Maquette.class);
            System.out.println("size 1: " + m1.gabarits.size());

            toCreateProj.save();

            Maquette m2 = new RushSearch().whereEqual("nom", selectedMaq.nom).findSingle(Maquette.class);
            System.out.println("size 2: " + m2.gabarits.size());

So my first System.out displays 3 (normal) and the second one displays 6 because of duplication

@Stuart-campbell

This comment has been minimized.

Show comment
Hide comment
@Stuart-campbell

Stuart-campbell Apr 28, 2015

Owner

From what you said looks like the join table might not be clearing. The tests are a little thin on chained relationships. I look into this in detail asap. Thanks for reporting it.

Owner

Stuart-campbell commented Apr 28, 2015

From what you said looks like the join table might not be clearing. The tests are a little thin on chained relationships. I look into this in detail asap. Thanks for reporting it.

@Stuart-campbell Stuart-campbell added the bug label Apr 28, 2015

@PaulineBAUDOUIN

This comment has been minimized.

Show comment
Hide comment
@PaulineBAUDOUIN

PaulineBAUDOUIN Apr 28, 2015

I managed to fix my problem by:

  • creating a new RushObject called Autorisation wich contains a Utilisateur and a List of Maquettes
  • removing the list of Maquettes in the Utilisateur RushObject

which makes that all the relations go only in one way !
It worked for me

PaulineBAUDOUIN commented Apr 28, 2015

I managed to fix my problem by:

  • creating a new RushObject called Autorisation wich contains a Utilisateur and a List of Maquettes
  • removing the list of Maquettes in the Utilisateur RushObject

which makes that all the relations go only in one way !
It worked for me

@Stuart-campbell

This comment has been minimized.

Show comment
Hide comment
@Stuart-campbell

Stuart-campbell Apr 28, 2015

Owner

So that confirms the bug is in the circular relationship.

Owner

Stuart-campbell commented Apr 28, 2015

So that confirms the bug is in the circular relationship.

@PaulineBAUDOUIN

This comment has been minimized.

Show comment
Hide comment
@PaulineBAUDOUIN

PaulineBAUDOUIN Apr 28, 2015

Yes indeed, thank you for helping me !

PaulineBAUDOUIN commented Apr 28, 2015

Yes indeed, thank you for helping me !

@Stuart-campbell Stuart-campbell changed the title from Duplicated RushObjects to Duplicated child RushObjects with circular relationships May 5, 2015

@HitOdessit

This comment has been minimized.

Show comment
Hide comment
@HitOdessit

HitOdessit Jul 29, 2015

@Stuart-campbell, any updates regarding fixing this bug?

HitOdessit commented Jul 29, 2015

@Stuart-campbell, any updates regarding fixing this bug?

@Stuart-campbell

This comment has been minimized.

Show comment
Hide comment
@Stuart-campbell

Stuart-campbell Jul 29, 2015

Owner

@HitOdessit been a little busy last week or so. Did find the time to put together a number of unit tests to attempt to pin point the bug with no luck.

Would you be able to share your data model in the most basic form and the order in which you save things see if I can get my tests to fail.

Sorry for the delay mix of weddings and release deadlines.

Thanks

Owner

Stuart-campbell commented Jul 29, 2015

@HitOdessit been a little busy last week or so. Did find the time to put together a number of unit tests to attempt to pin point the bug with no luck.

Would you be able to share your data model in the most basic form and the order in which you save things see if I can get my tests to fail.

Sorry for the delay mix of weddings and release deadlines.

Thanks

@HitOdessit

This comment has been minimized.

Show comment
Hide comment
@HitOdessit

HitOdessit Jul 29, 2015

@Stuart-campbell, sure, no problems, will provide you samples later today.

HitOdessit commented Jul 29, 2015

@Stuart-campbell, sure, no problems, will provide you samples later today.

@HitOdessit

This comment has been minimized.

Show comment
Hide comment
@HitOdessit

HitOdessit Jul 30, 2015

@Stuart-campbell Please look at the following project which can reproduce the error: https://github.com/nmoskalenko/rushorm_testing
We've tried to minimize amount of code, and also added some commets to help you understand the problem.

HitOdessit commented Jul 30, 2015

@Stuart-campbell Please look at the following project which can reproduce the error: https://github.com/nmoskalenko/rushorm_testing
We've tried to minimize amount of code, and also added some commets to help you understand the problem.

@Stuart-campbell

This comment has been minimized.

Show comment
Hide comment
@Stuart-campbell

Stuart-campbell Aug 3, 2015

Owner

@HitOdessit

Can you have a look at this unit test. As far as I can tell its identical to the project you created yet passes on api 14 and api 21 nexus 4 + 5

https://github.com/Stuart-campbell/RushOrm/blob/master/RushORM/app/src/androidTest/java/co/uk/rushexample/BugTests.java#L85-L113

Mapping of object names from the example

Bug29A -> E

https://github.com/Stuart-campbell/RushOrm/blob/master/RushORM/app/src/main/java/co/uk/rushexample/testobjects/Bug29A.java

Bug29B -> C

https://github.com/Stuart-campbell/RushOrm/blob/master/RushORM/app/src/main/java/co/uk/rushexample/testobjects/Bug29B.java

Bug29C -> P

https://github.com/Stuart-campbell/RushOrm/blob/master/RushORM/app/src/main/java/co/uk/rushexample/testobjects/Bug29C.java

I coming to a bit of a dead end on this one. Might be worth you pulling the project and trying to take a look yourself see if you can point me in the right direction.

Thanks

Owner

Stuart-campbell commented Aug 3, 2015

@HitOdessit

Can you have a look at this unit test. As far as I can tell its identical to the project you created yet passes on api 14 and api 21 nexus 4 + 5

https://github.com/Stuart-campbell/RushOrm/blob/master/RushORM/app/src/androidTest/java/co/uk/rushexample/BugTests.java#L85-L113

Mapping of object names from the example

Bug29A -> E

https://github.com/Stuart-campbell/RushOrm/blob/master/RushORM/app/src/main/java/co/uk/rushexample/testobjects/Bug29A.java

Bug29B -> C

https://github.com/Stuart-campbell/RushOrm/blob/master/RushORM/app/src/main/java/co/uk/rushexample/testobjects/Bug29B.java

Bug29C -> P

https://github.com/Stuart-campbell/RushOrm/blob/master/RushORM/app/src/main/java/co/uk/rushexample/testobjects/Bug29C.java

I coming to a bit of a dead end on this one. Might be worth you pulling the project and trying to take a look yourself see if you can point me in the right direction.

Thanks

@nmoskalenko

This comment has been minimized.

Show comment
Hide comment
@nmoskalenko

nmoskalenko Aug 3, 2015

@Stuart-campbell ,

the issue only partially fixed in 1.1.8

please look into update of the sample here - https://github.com/nmoskalenko/rushorm_testing
in you test, please check the Bug29A's list size after the test.
It's size expected to be 2, but actually 4.

nmoskalenko commented Aug 3, 2015

@Stuart-campbell ,

the issue only partially fixed in 1.1.8

please look into update of the sample here - https://github.com/nmoskalenko/rushorm_testing
in you test, please check the Bug29A's list size after the test.
It's size expected to be 2, but actually 4.

@Stuart-campbell

This comment has been minimized.

Show comment
Hide comment
@Stuart-campbell

Stuart-campbell Aug 3, 2015

Owner

Ah! I can not reproduce it and I finally think I know what could be the issue.

Should get it fixed tonight.

Thanks

Owner

Stuart-campbell commented Aug 3, 2015

Ah! I can not reproduce it and I finally think I know what could be the issue.

Should get it fixed tonight.

Thanks

@Stuart-campbell

This comment has been minimized.

Show comment
Hide comment
@Stuart-campbell

Stuart-campbell Aug 4, 2015

Owner

Fixed in v1.0.9

Owner

Stuart-campbell commented Aug 4, 2015

Fixed in v1.0.9

@nmoskalenko

This comment has been minimized.

Show comment
Hide comment
@nmoskalenko

nmoskalenko Aug 5, 2015

Just tested and can confirm fix in 1.1.9
Thanks Stuart!

nmoskalenko commented Aug 5, 2015

Just tested and can confirm fix in 1.1.9
Thanks Stuart!

@aercanozcan

This comment has been minimized.

Show comment
Hide comment
@aercanozcan

aercanozcan commented Aug 25, 2015

awesome!

gcalaprice added a commit to gcalaprice/RushCore that referenced this issue Oct 29, 2015

Merge branch 'master' of https://github.com/Stuart-campbell/RushCore
# By Stuart Campbell (9) and others
# Via Stuart Campbell
* 'master' of https://github.com/Stuart-campbell/RushCore:
  Fixes to RushPagingList
  Call LoadCallback after filling all object's fields
  Added boolean to get fields so they can be ordered.
  Fixed deadlock when saving empty list. Also resolved issue where queue was completed to early when saving over 1000 objects.
  Added whereIsNull and whereIsNotNull to RushSearch to allow querying for null fields
  Fixed Stuart-campbell/RushOrm#29
  Added better catching of classes not set.
  Fixed group by.
  Added group by
  Added where in
  Fixed issue where children were not loaded if the parent was joined to another child with the same id

Conflicts:
	rushcore.iml
	src/main/java/co/uk/rushorm/core/RushConfig.java

gcalaprice added a commit to gcalaprice/RushOrm that referenced this issue Oct 29, 2015

Merge branch 'master' of https://github.com/Stuart-campbell/RushOrm
# By Stuart Campbell
# Via Stuart Campbell
* 'master' of https://github.com/Stuart-campbell/RushOrm:
  Updated version number
  Updated rusher version added tests for bug 78
  Updated version number
  Stuart-campbell#73
  Updated version number
  Fixed Stuart-campbell#29
  Updated unit test for Stuart-campbell#29 to now fail. Fix soon.
  Updated version number
  RushCore updated v1.1.11
  Return rows from a child table that aren't connected to a parent? #61

Conflicts:
	RushORM/.idea/misc.xml
	RushORM/rushandroid/src/main/java/co/uk/rushorm/android/AndroidRushConfig.java
	pom.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment