Se alguem puder me dar uma luz aqui, agradeco. Quando eu executo essa query no H2 Console, eu recebo exatamente a saida que eu quero, mas quando rodo a mesma query pelo repositorio recebo uma exception.
Query no H2: SELECT inventory.inventory_id AS inventory_id, inventory.inventory_date AS inventory_date, inventory.item_amount AS item_amount FROM inventory JOIN item_inventory ON inventory.inventory_id = item_inventory.inventory_id WHERE item_inventory.item_id = [ID_QUE_ESTOU BUSCANDO];
Anotacao com o select no metodo do repositorio: @Query(nativeQuery = true, value = "SELECT inventory.inventory_id AS inventory_id, inventory.inventory_date AS inventory_date, inventory.item_amount AS item_amount FROM inventory JOIN item_inventory ON inventory.inventory_id = item_inventory.inventory_id WHERE item_inventory.item_id = :id") public List<Inventory> findInventoryByItem(@Param("id") Long id);
Exception que recebo do codigo: There was an unexpected error (type=Internal Server Error, status=500). Unable to find column position by name: item_id [Column "item_id" not found [42122-232]] [n/a]; SQL [n/a] org.springframework.dao.InvalidDataAccessResourceUsageException: Unable to find column position by name: item_id [Column "item_id" not found [42122-232]] [n/a]; SQL [n/a]
Eh estranho porque a tabela item_inventory
tem uma coluna chamada item_id
, mas o erro diz que nao tem. A tabela item_inventory
tem so duas colunas: inventory_id
e item_id
. Como que a mesma query roda no Console e falha no codigo?
update: testei usando Postgres e ainda assim recebo o mesmo erro: `There was an unexpected error (type=Internal Server Error, status=500).
Unable to find column position by name: item_id [The column name item_id was not found in this ResultSet.] [n/a]; SQL [n/a]
org.springframework.dao.InvalidDataAccessResourceUsageException: Unable to find column position by name: item_id [The column name item_id was not found in this ResultSet.] [n/a]; …
Caused by: org.hibernate.exception.SQLGrammarException: Unable to find column position by name: item_id [The column name item_id was not found in this ResultSet.] [n/a] …
Caused by: org.postgresql.util.PSQLException: The column name item_id was not found in this ResultSet.`