1
Using as an example a hotel booking app, I have something like
public class Reserva{
...
@CollectionTable(name = "custo_extras", joinColumns = @JoinColumn(name = "reserva_id"))
private List<CustoExtra> custosExtras;
...
}
@Embeddable
public class CustoExtra{
private BigDecimal valor;
private String descricao;
...
}
and an extra cost Repository
public interface ICustoExtraRepository extends JpaRepository<CustoExtra, Integer>
my point is, how I can query all the extra costs of a given reservation, or persist an extra cost of a reservation, since I don’t have a booking attribute in my extra cost class, which makes it impossible for me to make a method in Pository like
List<CustoExtra> findAllByReserva(Reserva reserva);
You have to always make the query in the entity ( in case a
Reserva
), not in theCustoExtra
. When using@Embeddable
you are saying that your entity has that structure. If you want to consult an entity calledCustoExtra
, the association must be made by means of foreign key– nullptr
I answered a question a while ago explaining these concepts of
@Embeddable
and@Embedded
, check here– nullptr