0

Suppose I have 3 classes Rose, Dandelion & Tulip. All of them are extending from the class Flowers, which again extends the class Plant. And I have a DataJPA interface that extends from JpaRepository<???????>, and has method save(Entity item).

Like this:

public class Rose extends Flower {
}
public class Dandelion extends Flower {
}
public class Tulip extends Flower {
}
public class Flower extends Plant {
}
public class Plant implements Persistable<Integer> {
}

public interface CrudFlowerRepository extends JpaRepository<?????????> {

    int delete(int flowerId);

    @Override
    <rerurn object> save(S item);

How properly write CrudFlowerRepository with generics when need object extends from Flower?

I try write CrudProductRepository<T, K extends TypedEntity> and other variants like this <s extends Plant> save(S item);. But my attempts failed. Thank for advice.

partlov
  • 13,789
  • 6
  • 63
  • 82
cori
  • 11
  • 3
  • How did you decide your CrudProductRepository parameter as CrudProductRepository, by extending the same logic, you can easily identify the typed methods and classes. – TruckDriver Aug 07 '17 at 10:15
  • Can you be more specific about the error that you are getting? – Dimitri Aug 07 '17 at 10:18
  • @Dimitri I just want ......save(new Tulip()) work directly similar as .....save(new Dandelion()). save(S item); in this place IDEA has warning – cori Aug 07 '17 at 10:31
  • @Timothy How to implement save(S item);? – cori Aug 07 '17 at 10:32
  • This may help: https://stackoverflow.com/questions/27543771/best-way-of-handling-entities-inheritance-in-spring-data-jpa – OutOfMind Aug 07 '17 at 11:49

0 Answers0