Question

Pourquoi la HQL suivante ne recherche pas un échec?

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

La même forme de requête fonctionne lorsqu'il est utilisé dans une sélection:

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

Le mappage pour MyLog contient:

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

Le mappage de la configuration contient:

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

L'erreur que je reçois est:

  

supprimer mylog, CONFIGURATION   countercon1_ où UTC_TIMESTAMP <: p0   et APPLICATION_ID =: p1; : = P0   10.04.2010 17:15:52,: p1 = 7

     

NHibernate.Exceptions.GenericADOException:   Impossible d'exécuter la requête de mise à jour [SQL:

     

supprimer mylog, CONFIGURATION   countercon1_ où UTC_TIMESTAMP      

] --->   Oracle.DataAccess.Client.OracleException:   ORA-00933: commande SQL pas correctement   terminé

Était-ce utile?

La solution

Essayez ceci:

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

Autres conseils

À partir du lien ci-dessus présenté par Rafael:

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

  

Non rejoint, implicite ou explicite,   peut être spécifiée dans une requête HQL.   Les sous-requêtes peuvent être utilisées dans le   clause where, où les sous-requêtes   elles-mêmes peuvent contenir des jointures

La syntaxe est DELETE FROM MyLog ....

Avoir à l'esprit que HQL suppression ne fonctionne pas cascades d'honneur définies avec (n) mise en veille prolongée mappings.

Vous pouvez sélectionner toutes les entités et les supprimer un par un.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top