0
Guys, I’m creating an API that will display random phrases from a table in the database.
The problem is that whenever I access the route, on the console, I get this exception:
org.H2.jdbc.Jdbcsqlexception: Column "id" not found [42122-197]
And in the Postman:
{
"timestamp": "2018-11-01T00:47:59.559+0000",
"status": 500,
"error": "Internal Server Error",
"message": "could not execute query; SQL [SELECT detail FROM scripts ORDER BY RANDOM() LIMIT 1]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query",
"path": "/v1/quote"
}
I am using the bank is the H2. In the folder resources
, there is a file schema.sql
, which contains the SQL for the table, and a data.sql
, with the data load.
Only the ID exists in the table scripts
, inside schema.sql
:
CREATE TABLE scripts (
id INTEGER PRIMARY KEY,
/* mais código*/
);
And exists in the class Quote
, that should map the class to table scripts
:
@Entity
@Table(name="scripts")
public class Quote {
@Id
@Column(name="id")
private Integer id;
/*Outra variáveis*/
/*Getters e Setters*/
}
Now I don’t know if I couldn’t map the table correctly...
The mapping of this table should be automatic, right?
Complete project on Github.
Table is being created correctly?
– Leonardo Lima
Hi, @Leonardolima! Thanks for commenting! So, yes, when I enter the H2 console, the table is and is populated with data from
data.sql
.– Van Ribeiro
@Leonardolima, the problem has been solved. I changed the way of doing the research. I modified it to pagination.
– Van Ribeiro