I am populating a dropdown with Company Name values using Hibernate but getting following compile time error:
Exceptionorg.springframework.orm.hibernate3.HibernateQueryException: company is not mapped [from company order by company_name]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: company is not mapped [from company order by company_name]
In database table name is company with column company_id as bigint,company_name as varchar My mapping file is:Company.hbm.xml as follows:
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Generated May 9, 2011 1:56:44 PM by Hibernate Tools 3.4.0.CR1 --> <hibernate-mapping> <class name="in.nic.pojo.Company" table="company" schema="mfms"> <id name="id" type="string"> <column name="company_id" /> <generator class="identity" /> </id> <property name="company" type="string"> <column name="company_name" /> </property> </class> </hibernate-mapping>
And the Company.java source file:
package in.nic.pojo;
import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType;
@XmlAccessorType(XmlAccessType.NONE) public class Company { // private String id; private String id; private String company; public Company() { super(); } public Company(String id, String company)
{ this.id = id; this.company = company; } public String getId() {
return id; } public void setId(String id) { this.id = id; }
public String getCompany() { return company; }
public void setCompany(String company) { this.company = company; } }
CompanyManagerImpl.java:
package in.nic.manager.impl;
import in.nic.manager.CompanyManager;
import in.nic.pojo.Company;
import in.nic.util.BaseException;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class CompanyManagerImpl extends HibernateDaoSupport implements CompanyManager { public List<Company> findAll() throws BaseException { System.out.println("hi--------------"); List<Company> companyList = getHibernateTemplate().find("from company order by company_name"); return companyList; } }
|