I have a database where I have countries table. The countries table has following structure.
CREATE TABLE `countries` (
`idCountry` int(5) NOT NULL AUTO_INCREMENT,
`countryCode` char(2) NOT NULL DEFAULT '',
`countryName` varchar(45) NOT NULL DEFAULT '',
PRIMARY KEY (`idCountry`)
) ENGINE=MyISAM AUTO_INCREMENT=252 DEFAULT CHARSET=utf8;
I have a hibernate Pojo which is configured properly in hibernate configuration file. The pojo looks like this
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "countries")
public class Country {
@Id
@Column(name = "id")
public int id;
@Column(name = "code")
public String code;
@Column(name = "name")
public String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
The database is already populated with list of all the countries and corresponding values. However when I try to get a contry from the table using the following code
SessionFactory sf = SessionFactoryUtil.getSessionFactory();
Session session = sf.openSession();
session.beginTransaction();
Country c = (Country) session.get(Country.class, 105);
return c;
I am getting the following exception
[org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'country0_.id' in 'field list'