google-code-export / morphia

Automatically exported from code.google.com/p/morphia
1 stars 0 forks source link

embedded classes are pointing to a single object reference for each type #283

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What version are you using? (Morphia/Driver/MongoDB)
Morphia 1.0-SNAPSHOT

Problem:
Embedded Classes are pointing to a single object reference - which gets 
overwritten every time a new object of that type is requested - even if the 
request was for a totally different parent class.

Repro Steps:

i have a 3 container classes - 1 parent and 2 child classes:

ContainerClass{

  ChildContainer container
}

ChildOne extends ChildContainer{
  String myproperty
}
ChildTwo extends ChildCOntainer{
 String myotherproperty
}

i now have a database with the following entries:

Containerclass id:1 - ChildOne - myproperty: test 1
Containerclass id:2 - ChildOne - myproperty: test 2
Containerclass id:3 - ChildTwo - myproperty: test 3
Containerclass id:4 - ChildTwo - myproperty: test 4

if i place a query.asList() on that table i get this result:

Containerclass id:1 - ChildOne - myproperty: test 2
Containerclass id:2 - ChildOne - myproperty: test 2
Containerclass id:3 - ChildTwo - myproperty: test 4
Containerclass id:4 - ChildTwo - myproperty: test 4

as we see the embedded class is overwritten everywhere with the last result 
which was returned from a parent object.
My woraround was to request every object one-by-one and invoke a 
parent.container = parent.container.clone() on every returned instance.

Original issue reported on code.google.com by alexande...@gmail.com on 6 Jun 2011 at 1:53

GoogleCodeExporter commented 9 years ago
ah and the ChildContainer class is Abstract ... in case this makes a difference 
...

Original comment by alexande...@gmail.com on 10 Jun 2011 at 2:24

GoogleCodeExporter commented 9 years ago
seems to be related to Issue 281

Original comment by alexande...@gmail.com on 14 Jun 2011 at 8:27

GoogleCodeExporter commented 9 years ago
got this fixed on my side - was an issue with singleton objects being 
initialized through spring - please close

Original comment by alexande...@gmail.com on 14 Jun 2011 at 11:28

GoogleCodeExporter commented 9 years ago

Original comment by scotthernandez on 18 Jun 2011 at 11:50