我是使用 Spring/hibernate 的初学者。我在一个方法中编写了以下查询,以便该方法根据查询结果返回一个布尔值。
public Boolean getStatus(){
logger.debug("Get Emp Status");
Session session = sessionFactory.getCurrentSession();
String hql = "SELECT ec.IsEnable FROM Employee ec WHERE ec.UID=1";
Query query = session.createQuery(hql);
Boolean result = (Boolean) query.uniqueResult();
return result;
}
员工实体:
@Entity
@Table (name = "FS_Employee")
public class Employee {
@Id
@GeneratedValue
@Column (name = "UID")
private Integer UID;
@Column (name = "IsEnable")
private Boolean IsEnable;
public Employee(){ }
/**
* @return
*/
public Boolean getIsEnable()
{
return IsEnable;
}
/**
* @param boolean1
*/
public void setIsEnable(Boolean boolean1)
{
IsEnable = boolean1;
}
/*
*sets value of UID
*
* @param Integer
*/
public void setUID(Integer UID){
this.UID = UID;
}
/*
*gets value of UID
*
* @param
*/
public Integer getUID(){
return UID ;
}
}
休眠上下文.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
">
<context:property-placeholder location="/WEB-INF/spring.properties" />
<!-- Enable annotation style of managing transactions -->
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
p:dataSource-ref="dataSource"
p:configLocation="/WEB-INF/hibernate.cfg.xml"
p:packagesToScan="test"/>
</beans>
休眠.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="show_sql">false</property>
</session-factory>
</hibernate-configuration>
这不起作用,我收到以下错误。
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.QueryException: could not resolve property: IsEnable of: test.spring.model.Employee [SELECT ec.IsEnable FROM test.spring.model.Employee ec WHERE ec.UID=1]
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:656)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
对此的任何帮助将不胜感激。