Please help me please, I have a problem here and I'm banging my head to resolve this for hours. I use Spring in the project and I have the following relationship in one of my models:
@OneToOne()
@JoinColumn(name = "ITE_COD_INTERNO")
@NotFound(action = NotFoundAction.IGNORE)
@Getter @Setter
private ItemPreco preco;
In the ItemPreco I have this:
@OneToOne(mappedBy = "preco")
@Setter
private Item item;
My ItemPreco class has two main fields:
@Id
@Column(name = "TPC_COD_INTERNO")
@Getter @Setter
private String itemId;
@Column(name = "TPC_UNIDADE")
@Getter @Setter
private String unidade;
My repository that performs the query is as follows:
@Query("SELECT i FROM Item i "
+ "WHERE i.grupo.visivel = :visivel "
+ "AND i.preco.unidade = :unidade "
+ "AND i.itemId = :itemId "
+ "AND i.preco.preco <> 0 "
+ "ORDER BY i.descricao")
Item findByItemIdAndVisivelAndUnidade(@Param("itemId") String itemId, @Param("visivel") boolean visivel, @Param("unidade") String unidade);
The feedback I receive is a line from a "random" drive rather than the one I've been looking for. Example: I searched for drive 001 and I get drive 002.
And what I want is to fetch an item and its price, which has a OneToOne relationship if searched for by internal code + drive.
If someone can give me a light on how to solve this, I thank you, thank you in advance!