Aossey
Aossey

Reputation: 935

Morphia with Abstract Class Annotation

I am trying to understand how to properly annotate a base class and the extending class with Morphia. Given the following example would I @Entity to the Employee class or just the Developer class?

public abstract class Employee {
    @Property
    private String firstName;
    @Property
    private String lastName;
    @Property
    private Date startDate;
}


@Entity
public class Developer extends Employee{

    @Embedded
    private List<String> ProjectList;

}

Upvotes: 0

Views: 935

Answers (1)

xeraa
xeraa

Reputation: 10859

  1. You don't need the @Property annotations
  2. If you want to use different collections for the subclasses, this is fine. If you want to use a single collection for all subclasses, you would only need to annotate Employee. Since you don't have a schema, both approaches are perfectly fine and it only dependes on how you want to access your data later on.

Upvotes: 1

Related Questions