John Ellis
John Ellis

Reputation: 213

Underscore in table name using Spring and MSSQL

I need to use a custom query for my application so this is my simplified code:

List<myDAO> findByName (
    String Name
);


@Query("SELECT Company, count(Name) FROM my_table GROUP BY Company")
List<myDAO> getNamesOfCustom (
    String Name
);

The first query works fine, the second is not, and I'm getting:

org.hibernate.hql.internal.ast.QuerySyntaxException: my_table is not mapped

I specified the table name in my DAO. Could the problem be with the table name if the first query is working?

Upvotes: 0

Views: 743

Answers (1)

ewramner
ewramner

Reputation: 6233

You need to specify that you want a native SQL query:

@Query(
  value = "SELECT Company, count(Name) FROM my_table GROUP BY Company", 
  nativeQuery = true)

Alternatively if you don't want a native query you should use the entity name, not the table name.

Upvotes: 1

Related Questions