I would like to receive all of the records, which extend from my abstract class. I have the following:
Product.java
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@DiscriminatorColumn(name="descriminatorColumn")
@Table(name="ProductCatalog")
public abstract class Product {
@Id
private Long id;
}
PC.java
@Entity
@Table(name = "PC")
public class PC extends Product{
private String pcType;
}
TV.java
@Entity
@Table(name = "TV")
public class TV extends Product{
private String tvType;
}
And ProductRepository.java
public interface ProductRepository extends CrudRepository<Product, Long> {
<T extends Product>List<T> findAll(); // not working
}
In my controller I have:
@RequestMapping(value = "/product", method = GET)
public <T extends Product>List<T> findProducts(){
return productRepository.findAll();
}
How can I make the findAll()
return all of the items from the subclasses that extend class Product
?
UPDATE:
I have added the following method to the ProductRepository:
<T extends Product>List<T> findProducts();
and changed it in the controller - is this the proper way to do it ?
The error that I've using this is:
Caused by:
org.springframework.data.mapping.PropertyReferenceException: No
property findProducts found for type Product!