2011-12-14 6 views
0

ガットの例外要因更新します。このコードが実行されたときに
休止状態:MappingException)(getHibernateTemplateを実行すると、クエリに

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}); 
} 

EDIT

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はOKあまりに:getHibernateTemplate().updateはメソッドではなくSQLクエリにObjectを渡すことを前提としているため

<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メソッドを実行する方法、です。

+0

完全修飾クラス名を使用してください。さらに詳細を追加してください。 –

+0

@ slayer_bあなたはそれにパッケージ宣言を付けることを提案しますか? – sergionni

+0

はい。エンティティ、構成、DAOを投稿すると、全体のクラスを意味します。それは構成上のエラーのようです。 –

答えて

0

Hibernate ORM経由でアップデートを実行するために、私はこのような構成を使用:

SessionFactory sf = getHibernateTemplate().getSessionFactory(); 
Session s = sf.openSession(); 
Query q = s.createQuery("UserDetails set confirmed=true 
where username:username and confirmationCode=:confirmationCode"); 
q.setString("username", username); 
q.setString("confirmationCode", confirmationCode); 
q.executeUpdate(); 

それが原因getHibernateTemplate().updateに、行われていたという名前のparamsを許可していません。
オブジェクトが渡される必要があります。