I am experimenting with Springboot, I have several entities with several properties that are very similar, example: The entity "Car" has model and price properties so do the "Motorcycle" model. I would like to use a a class to define just those common attributes, class "Vehicle" with the properties model and price.
In another words:
Car Motorcicle Vehicle
price price price
model model model
year year
color color
fuel_type fuel_type
... 30 more properites ...30 more properties
I want to use vehicle to map the search result of a SQL union between Car and Motorcycle tables.
public interface ImovelRepositorio extends JpaRepository<Vehicle, Long> {
@Query(value = "here select query with union between car and motorcycle", nativeQuery = true)
List<Vehicle> searchVehicle();
}
Here Vehicle class is a normal class without any annotation. I am getting errors saying that Vehicle is not managed type. Of course my repository doesn't make sense, I expected this error. But how can I achieve what I want?
When I perform a union I am not getting a list of models and am getting a list of one or more models. I want to create a class to "combine" the result of a search.