An alias is required for the schema name MyEntity in the expression.

Yesterday I came across the following error message while testing a JPQL named query

    An alias is required for the schema name MyEntity in the expression…

A quick Yahoo! search only returned me something like this which isn’t very useful. Anyway, the solution was extremely simple: my name query was incorrect. Instead of writing

 select ent from MyEntity ent where ent.status.code = : code

I had written

 select ent from MyEntity where ent.status.code = :code

Because I had forgotten to declare the variable ‘ent’ I suppose OpenJPA expected it to be a schema name or something.

Advertisements

4 thoughts on “An alias is required for the schema name MyEntity in the expression.

  1. Thanks, after nearly an hour of trying to figure out why my query wasn’t working your post pointed me to the problem!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s