Thursday, June 14, 2012

QuerySyntaxException: MyObject is not mapped

I came across this beauty of an error when trying to use a Spring Data @Query annotation.  I could see the mapping in the hibernate configuration and it seemed to work in other places so why in the world was my query saying that my object now isn't mapped??

Well, after some fiddling around I noticed that the entity object only had @Entity(name = "table_name").

After adding the @Table(name = "table_name")  and removing the name from the @Entity it started working.

Also for the record it also worked if I used the complete class name in the query, ie @Query("select c from com.package.ClassName c")

1 comment:

  1. I have the same issue, but even though I follow your tip I'm still getting this problem. I have some integration tests with Spring and for some reason it does not find any entity classes on test-source folder.

    My entity classes are found and work fine on Eclipse but not in Ant script (all classes are in classpath properly). This is weird!

    ReplyDelete