Given the following classes:
@MappedSuperclass
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
@DiscriminatorColumn(name="animalType",discriminatorType=DiscriminatorType.STRING)
@QueryExclude
public abstract class Animal {}
@Entity
@DiscriminatorValue("dog")
public class Dog {}
@Entity
@DiscriminatorValue("cat")
public class Cat {}
Is it possible somehow to configure a JPA Repository for Animal
?
I've tried
public interface AnimalRepository extends JpaRepository<Animal,Long>
However this fails with:
java.lang.IllegalArgumentException: Not an managed type: Animal
Is there a way to configure this?
I'd like to be able to perform tasks like:
@Autowired
private AnimalRepository repository;
public void doSomething()
{
Animal animal = repository.findById(123);
animal.speak();
}
I had similiar error. I solved it by adding mapping of my entity class to my persistence.xml file.
So maybe add something like this to your persistence.xml:
<persistence-unit>
...
<class>yourpackage.Animal</class>
...
</persistence-unit>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With