SQL error: 17006, sqlstate: 99999 invalid column name

SQL Error: 17006, SQLState: 99999 invalid column name

reported an error when using hibernate for query today. This is simply recorded here.

problem description:

USES hibernate to query an entity for an error.

reason analysis:

	String sql = "select emplId,name  from employee";
	try {
		Session session = sessionFactory.getCurrentSession();
		SQLQuery query = session.createSQLQuery(sql.toString());			
		query.addScalar("emplId", StringType.INSTANCE);			
		query.addScalar("emplName", StringType.INSTANCE);
		query.setResultTransformer(Transformers.aliasToBean(Employee.class));
		employeeList = query.list();
		}
		......

The field for the

SQL query is name, and the field for the entity is emplName. Name inconsistency results.

solution:

	String sql = "select emplId, name as emplName from employee";
	try {
		Session session = sessionFactory.getCurrentSession();
		SQLQuery query = session.createSQLQuery(sql.toString());			
		query.addScalar("emplId", StringType.INSTANCE);			
		query.addScalar("emplName", StringType.INSTANCE);
		query.setResultTransformer(Transformers.aliasToBean(Employee.class));
		employeeList = query.list();
		}
		......

Read More: