D
D
DarkByte20152017-07-27 20:22:36
Java
DarkByte2015, 2017-07-27 20:22:36

Why does the query fail?

I use H2, Spring and Hibernate. The query is extremely simple "select v from LegalEntity as v". Those. select all data from the table. And here is another table schema if necessary, also very simple:

create table if not exists LegalEntity (
  id int primary key auto_increment,
  version int not null,
  name varchar(50) not null,
  inn varchar(50) not null
);

But the following error is thrown:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not prepare statement; SQL [select legalentit0_.id as id1_2_, legalentit0_.inn as inn2_2_, legalentit0_.name as name3_2_, legalentit0_.version as version4_2_ from legal_entity legalentit0_]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement

What is the problem?
PS Some strange SQL it generates... It's like I'm writing HQL (I haven't figured it out yet). So basically the challenge is:
em.createQuery("select v from LegalEntity as v", LegalEntity.class).getResultList();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Kuznetsov, 2017-07-28
@DarkByte2015

Do you have such a table in your database file? Make sure of this, and also that her name is correctly mapped.
PS Your mistake here it is -

Caused by: org.h2.jdbc.JdbcSQLException: Таблица "LEGAL_ENTITY" не найдена
Table "LEGAL_ENTITY" not found; SQL statement:
select legalentit0_.id as id1_2_, legalentit0_.inn as inn2_2_, legalentit0_.name as name3_2_, legalentit0_.version as version4_2_ from legal_entity legalentit0_

That error which you have specified, it arising at a following level.
PPS https://stackoverflow.com/questions/33519630/h2-jd...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question