0

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?

4
  • Specified where and how? Commented Feb 25, 2019 at 14:32
  • Maybe you need an alias in the second field SELECT Company, count(Name) as field_name FROM my_table GROUP BY Company Commented Feb 25, 2019 at 14:39
  • Is the table schema different from dbo? Is the connection mapped to a different database? Commented Feb 25, 2019 at 14:43
  • I think you need to use the entity name rather than the table name as it seems to be a normal query, not a native SQL query? Commented Feb 25, 2019 at 14:45

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! That's what I was missing

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.