Question

Imagine that we have :

public class Person {...}
public class Employee extends Person {....}

We make of Employee an entity that have an other table as Person.
With JPA we make our interface extends JpaRepository.

I ask the personRepo.findAll()

Is it possible to get only the List of Person without the Employees? (I'm analysing this atm so I don't have concreet example, just need to know if this is possible)

Thx in advance

Was it helpful?

Solution

I did the same thing. This is my code:

@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@Audited
public abstract class AbstractUser{..}

@Entity
@Audited
public class Admin extends AbstractUser{ .. }

@Entity
@Audited
public class OtherUser extends AbstractUser{ .. }

And then, I use Repository too. So if I use yoursRepository.findAll(); I get all Users..

In your case, with personRepo.findAll(), you get all person.. You get all those that extend person and those that do not extend it.

EDIT: after question edit If you want get only employee you can use two different repository, one for Employee and one for Person. So when you use employeeRepository, you get only employee..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top