【发布时间】:2011-12-14 16:29:26
【问题描述】:
得到异常原因:
org.hibernate.MappingException: Unknown entity: UserDetails set confirmed=true where username=? and confirmationCode=?
这段代码何时执行:
public void confirmUser(String username,String confirmationCode){
getHibernateTemplate().update("UserDetails set confirmed=true where username=? and confirmationCode=?",new Object[]{username,confirmationCode});
}
编辑
This query works OK:
public String getUserMail(String username) {
return (String) DataAccessUtils.uniqueResult(getHibernateTemplate().find(
"select mail from UserDetails where username=?", new Object[] { username }));
}
这意味着,我的hbm.xml 也应该没问题:
<hibernate-mapping>
<class name="model.UserDetails" table="users">
<id name="id">
<generator class="increment"/>
</id>
<property name="username" column="username"/>
<property name="password" column="password"/>
<property name="enabled" column="enabled"/>
<property name="mail" column="mail"/>
<property name="city" column="city"/>
<property name="confirmed" column="confirmed"/>
<property name="confirmationCode" column="confirmation_code"/>
<set name="authorities" cascade="all" inverse="true">
<key column="id" not-null="true"/>
<one-to-many class="model.Authority"/>
</set>
</class>
</hibernate-mapping>
问题是,如何使用一组参数执行update 方法,因为getHibernateTemplate().update 假定将Object 传递给方法,而不是SQL 查询。
【问题讨论】:
-
尝试使用完全限定的类名。并添加更多细节。
-
@slayer_b 你建议在它前面加上包声明吗?
-
是的。发布您的实体,配置,dao 我的意思是整个班级。因为似乎配置中有错误。
-
我已经更新了帖子。实际上其他查询工作正常,使用
UserDetails映射(请参阅编辑部分)。 -
也许,问题出在
getHibernateTemplate().update方法上。找不到合适的例子。在大多数例子中使用session.saveOrUpdate。
标签: hibernate exception mapping