MorphiaOrg / MorphiaOrg/morphia

@PrePersist of parent class called on embedded values that do no inherit any @PrePersist methods

Open
#2,202 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

  • #2227 by @zenbones — closed without merging
bug Waiting for Response
Dominant language
Java
Stars
1.7k
Forks
449
Avg merge
7m
Merged PRs (30d)
10

Description

With 2.3.0 I have a base class...

pubic abstract class Durable<I> {

  @Id
  private I id;

  @Override
  public I getId () {

    return id;
  }

  @Override
  public void setId (I id) {

    this.id = id;
  }

  @PrePersist
  public void prePersist (final DBObject dbObj) {

  ... stuff I need to do ...
  }
}

...and an entity that extends the base class...

@Entity(value = "something", useDiscriminator = false)
public class Something extends Durable<ObjectId> {

  @Property("child")
  private Child child;

  public Child getChild () {

    return child;
  }

  public void setChild (Child child) {

    this.child  = child;
  }
}

...and finally the child...

@Entity
public class Child {
...
}

So, Something has the @PrePersist method inherited from Durable, and Child has no pre persist, but during an update executed to create a new Something the prePersist method from Durable is called with Child as a target, from dev.morphia.mapping.codec.pojo.ClassMethodPair : 61, which fails with ...

Error in process java.lang.IllegalArgumentException: object is not an instance of declaring class

...probably because Child is not a Durable and should not be pre-persisted.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at dev.morphia.mapping.codec.pojo.ClassMethodPair around line 61 and reproduce the update that creates a Something containing a Child. The fix is done when Durable's inherited @PrePersist method is not invoked for the embedded Child and the update completes successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, mongodb
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.