I am just curious what the o stands for when I am trying to query.
By default my query is coming out as
@NamedQuery (name="newName" query=SELECT o FROM tableView o)
I am just curious what the o stands for. I have seen several instances of using the letter x and c as well. Just wondering what the difference, if any. Also, why can’t I just use a * to select and entire row?
It is called identification variable in JQPL terminology. When used in SELECT statements, identification variable is declared in FROM clause. It is mandatory to use it in SELECT statement if some persistent attribute (of entity), entity itself, or some value deduced from persistent attribute is designed as a result of query.
Same queries without using
a.are not valid JQPL queries. They do work in Hibernate, because HQL as a query language does have quite a bunch of extensions.Need for identification variable comes obvious when query contains more than one entity with identical names of attributes:
As you see from the query above, identification variable are also used in WHERE clause. Following quote from JPA 2.0 specification sums up also other uses and declaration of them quite tightly:
Naming of identification variable is quite free, but it should not be any reserved identifier or name of the entity.
You cannot use ‘SELECT *’, because JPQL does not have such a construct. It is also often considered as an anti pattern in SQL not to specify explicitly list of values to be selected. It would for example need to redefine what is selected when join is added to query.