0

We have a table with a composite primary key mapped, as shown below:

mapping.CompositeId().KeyReference(e => e.Node).KeyProperty(e => e.DtFr).UnsavedValue("any");

We need to delete several rows from the table by complex condition, for example n.Node.Contract.Code = "1234"

According to the solution we tried next HQL:

delete from Entity n where n in (select c from Entity c where c.Node.Contract.Code = "1234")

But in the generated SQL-query there are no parentheses around the primary key columns:

select ... from ENTITY n where n.IDNODE, n.DTFR in (select c.IDNODE, c.DTFR ...

We tried explicitly to add parentheses in HQL (where (n) in), but NHibernate ignores them.

What can we do to make NHibernate generate the correct SQL?

Version of NHibernate is 4.1.1.4000, RDBMS is Oracle 10.2.

SQL dialect is set to NHibernate.Dialect.Oracle10gDialect.

user2291296
  • 334
  • 3
  • 11

1 Answers1

1

It is very likely there is a bug in NHibernate. Issue is added: https://github.com/nhibernate/nhibernate-core/issues/1376.

So for now the only solution is: load all the entities you want to delete and then delete them.

var entities2delete = session.CreateQuery("select c from Entity c where c.Node.Contract.Code = \"1234\"").List();
foreach (var item in entities2delete) session.Delete(item);
user2291296
  • 334
  • 3
  • 11