Exception of query syntax, table name not mapped

advertisements

I'm using HQL query, pls see the below code.

Entity class:

@Entity
@Table(name = "COUNTRY")
public class Country implements Serializable{

private long countryCode;
private String countryName;

DAO:

public List<Country> getCountryList(){
    List<Country> resultList = null;
    System.out.println("in dao");
    Query query = getSession().createQuery(" from country ctry ");
    resultList =  query.list();

    return resultList;
}

app context.xml:

<beans:property name="annotatedClasses">
  <beans:list>
      <beans:value>com.test.in.ergy.entity.Country</beans:value>
  </beans:list>
</beans:property>

What might be the problem


If you use createQuery from Query class, Hibernate is case sensitive but regarding the class name that you are trying to retrive...not to the table

for example

Query query = session.createQuery("from Airplane"); will work if the name of the class is "Airplane"

Query query = session.createQuery("from AIRPLANE"); it will fail no matter if the table name in DB is AIRPLANE, because it will look for the class, not the table