0

I have one column "MESSAGE REECEIVED FROM" in sql server. In my springboot application fetching the column names from Entity bean.

Declared column name as below in entity bean

  @Column(name="[MESSAGES REECEIVED FROM]")
  private String messagesReeceivedFrom = null;

and while connecting to the database, getting the error as below

   SQL Error: 207, SQLState: S0001
   Invalid column name 'REECEIVED'.

but while executing the same column in sql server query is executing.

Help me in interpreting the sql reserved keywords while calling through jpa

  • 1
    Enclose column names in backtick. (`) – marekful Oct 27 '17 at 05:07
  • tried with this option, then application it self is not starting. throwing exception `"org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.boot.model.naming.IllegalIdentifierException: Identifier text should not contain quote markers (` or ")` – hari kishan Oct 27 '17 at 05:40
  • Check [this](https://stackoverflow.com/questions/2224503/creating-field-with-reserved-word-name-with-jpa) out. In short: to let JPA know that the column name should be escaped, enclose it in quotes, not the DB-specific delimiter, i.e. `@Column(name="\"MESSAGES RECEIVED FROM\"")`. Also there is a spelling error - "RECEEIVED" while you mention that the column is named "RECEIVED". – Nikos Paraskevopoulos Oct 27 '17 at 08:09
  • Had corrected the question @Nikos. i tried with the option you provided, below exception is raised `Invalid column name 'REECEIVED'. [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause` – hari kishan Oct 27 '17 at 09:40
  • Make sure the spelling is correct - `RECEEIVED`/`RECEIVED`! – Nikos Paraskevopoulos Oct 27 '17 at 12:08
  • Spelling in correct with the database column exist as `MESSAGES RECEEIVED FROM`. i dont think spelling will cause the issue – hari kishan Oct 30 '17 at 13:37

0 Answers0