質問

なぜ次のHQLクエリが失敗するのですか?

string hql = @"delete MyLog log
               where
                    log.UtcTimestamp < :threshold and
                    log.Configuration.Application = :application";

session.CreateQuery(hql)
       .SetDateTime("threshold", threshold)
       .SetEnum("application", this.application)
       .ExecuteUpdate();

同じ形式のクエリは、selectで使用する場合に機能します。

string hql = @"from MyLog log
               where
                    log.UtcTimestamp < :threshold and
                    log.Configuration.Application = :application";
IList<MyLog> log = session.CreateQuery(hql)
    .SetDateTime("threshold", threshold)
    .SetEnum("application", this.application)
    .List<MyLog>();

mylogのマッピングには次のものが含まれています。

References(x => x.Configuration)
     .Columns("CONFIGURATION_ID")
     .ReadOnly();      

構成のマッピングには次のものが含まれます。

Map(x => x.Application, "APPLICATION_ID");

私が得るエラーは次のとおりです。

MyLogから削除、Configuration CounterCon1_ここで、UTC_TIMESTAMP <:P0およびApplication_ID =:P1; :p0 = 04/10/2010 17:15:52、:p1 = 7

nhibernate.exceptions.genericadoexception:更新クエリを実行できませんでした[sql:

mylogから削除、Configuration countercon1_ここでutc_timestamp <?およびapplication_id =?

] ---> oracle.dataaccess.client.oracleException:ora-00933:sqlコマンドが適切に終了していない

役に立ちましたか?

解決

これを試して:

delete MyLog log
where log.id in
          (select l.id
           from MyLog l
           where l.UtcTimestamp < :threshold and
           and.Configuration.Application = :application)

他のヒント

上記のラファエルが提出したリンクから:

http://docs.jboss.org/hibernate/stable/core/reference/en/html/batch.html#batch-direct

暗黙的または明示的な結合は、バルクHQLクエリで指定できません。サブQueriesは、条件で使用することができます。ここでは、サブQueries自体に結合が含まれている場合があります。

構文はです DELETE FROM MyLog ....

HQL Deleteは(n)冬眠マッピングで定義されたカスケードを尊重しないことに留意してください。

そのため、すべてのエンティティを選択して、1つずつ削除できます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top