Using jboss5.1.x, ejb3.0
This was driving me crazy for two day now:
I am trying simple where clauses query and I keep on getting that error:
this is what I get with JPSQL query:
String queString ="select s from T04SysParms s WHERE s.key_Name='EXECUTION_TIME'";
Query q = em.createQuery(queString);
List<T04SysParms> results = (List<T04SysParms>) q.getResultList();
exception I get:
org.hibernate.QueryException: could not resolve property: key_Name of: com.mirs.ecms.db2.T04SysParms [select s from com.mirs.ecms.db2.T04SysParms s WHERE s.key_Name=’EXECUTION_TIME’]
this is my mappe class:
@Entity
@Table(name = "T04_SYS_PARMS", schema = "ECMS")
public class T04SysParms implements java.io.Serializable
{
// Fields
private String key_Name;
private String value_Name;
// Constructors
/** default constructor */
public T04SysParms()
{
}
/** minimal constructor */
public T04SysParms(String keyName)
{
this.key_Name = keyName;
}
/** full constructor */
public T04SysParms(String keyName, String valueName)
{
this.key_Name = keyName;
this.value_Name = valueName;
}
// Property accessors
@Id
@Column(name = "KEY_NAME", unique = true, nullable = false, length = 100)
public String getKeyName()
{
return this.key_Name;
}
public void setKeyName(String keyName)
{
this.key_Name = keyName;
}
@Column(name = "VALUE_NAME", length = 200)
public String getValueName()
{
return this.value_Name;
}
public void setValueName(String valueName)
{
this.value_Name = valueName;
}
}
The actualy table name in database: T04_SYS_PARMS
the mapped table name is: T04SysParms
any idea?
thanks,
ray.
VALUEis a reserved word in the sql standard. Do you actually have a column named that? If so, you might need to quote it in the query. Or better, change it to a more meaningful name.Based on comments, this was likely not the root problem, though I think it’s healthy to avoid reserved words.
You’ve also been showing queries that get only the VALUE_NAME field, but then you’re trying to pull a whole T04SysParms out of the result.
Based on the update including the mappings, a JPQL version of the query:
should give you back a list of T04SysParms objects conforming to your needs.
It should be possible to do something similar with the SQL form (adjusting it to get all fields), but to get entities rather than individual fields, JPQL is more appropriate.