Skip to content

Is Entity Inheritance Possible with a single Repository? #126

Open
@pluttrell

Description

@pluttrell

Is there a way to use a single Repository to produce multiple types that inherit from an abstract class if they are stored in a single table? For example if Cat and Dog both extend Animal and are both stored in a table called Animals? The single Repository would need instantiate the proper type when returning instances.

JPA supports this with @Inheritance(strategy = SINGLE_TABLE), @DiscriminatorColumn and @DiscriminatorValue as shown here: https://saurabh1.com/2015/04/14/inheritance/. I've tried this example but it fails with this error:

Caused by: java.lang.InstantiationException: example.Animal
	at java.lang.Class.newInstance(Class.java:427)
	at com.amazonaws.services.dynamodbv2.datamodeling.StandardBeanProperties$DeclaringReflect.newInstance(StandardBeanProperties.java:183)
	... 34 more
Caused by: java.lang.NoSuchMethodException: example.Animal.<init>()

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions