-
1. Re: Aliases in Queries
mazz Feb 24, 2007 4:49 PM (in response to micho)This is saying your User object does not have a "peter" attribute.
I think you want something like:
"from User u where u.name = :name"
and you setParameter("name", "pete").
I assume your User object has an attribute "name" (i.e. User.getName()) and I assume your User doesn't have a User.getPeter() :) -
2. Re: Aliases in Queries
micho Feb 24, 2007 4:58 PM (in response to micho)I exchanged the two codeexamples.
if there is no attribute "peter" why does the query"from User where (peter = :name)"
work.
If I add the alias u and writefrom User u where (u.peter = :name)
I get the exception.
I coded the attribute like this:@Column(name = "peter") public String getHugo() { return mHugo; }
-
3. Re: Aliases in Queries
mazz Feb 24, 2007 5:09 PM (in response to micho)First, as I understand it, the @Column annotation defines the actual database column name but has no bearing on how the ORM tool identifies this column in the JPQL query language.
@Column(name = "peter")
public String getHugo()
This entity's column is "Hugo" when you identify it in your JPQL queries. "peter" is the actual name of the column in the database, and is used when the JPA implementation (Hibernate in JBoss EJB's case) builds the actual SQL that it sends to the database. So, I definitely see why u.peter fails - it should be u.hugo.
I don't know what that first query is doing... "peter = :name". Turn on Hibernate SQL debugging (show_sql=true) to look at the actual SQL its issuing - that usually tells you alot about what's happening. -
4. Re: Aliases in Queries
micho Feb 24, 2007 5:28 PM (in response to micho)Thanks for your answer.
How do I have to name the property an a query in my example@Column(name = "peter") public String getHugo() { return mHugo; }
peter, Hugo, mHugo
the doku saysThe logical column name is defined by the Hibernate NamingStrategy implementation. The default EJB3 naming strategy use the physical column name as the logical column name. Note that this may be different than the property name (if the column name is explicit). Unless you override the NamingStrategy, you shouldn't worry about that.
I understood that the pysical name is the name in the database, that´s wrong?from User as u where (u.Hugo = :name)
throws the same exceptionfrom User where (Hugo = :name)
throws a grammar exception.
The query, thats ok"from User where (peter = :name)") .setParameter ("name", "y")
retrieves all User Objects with paremater "peter" = "y"
How can I turn on the SQL debugging. -
5. Re: Aliases in Queries
micho Feb 24, 2007 8:25 PM (in response to micho)thanks
from User u where (u.hugo = :name)
works