NHibernate implicit join quirk

Recently I had a problem where in an HQL query the result contained duplicates. I used implicit joins in the my query and it looked like the following:

from
    Order o
where
    (o.Code like :literal
    OR o.CustomData like :literal
    OR o.Customer.Code like :literal
    OR o.Customer.Name like :literal)

This HQL got translated to the following TSQL query:

select
    order0_.* — all order columns removed for readability
from
    nhtest.dbo.Order order0_,
    nhtest.dbo.Customer customer0_
where
    (order0_.Code like @p0 )
    OR(order0_.CustomData like @p1 )
    OR(customer0_.Code like @p2  and order0_.CustomerId=customer0_.Id) — Incorrect join!
    OR(customer0_.Name like @p3  and order0_.CustomerId=customer0_.Id) — Incorrect join!

The join isn’t correct as it should have been the following:

select
    order0_.* — all order columns removed for readability
from
    nhtest.dbo.Order order0_,
    JOIN nhtest.dbo.Customer customer0_ ON (order0_.CustomerId=customer0_.Id)
where
    order0_.Code like @p0 )
    OR(order0_.CustomData like @p1 )
    OR(customer0_.Code like @p2)
    OR(customer0_.Name like @p3)
)

The (N)Hibernate documentation says that it is better to make use of the explicit join syntax and that is working correct. So do not use implicit joins (well, atleast not in version 2.0.0.GA)!

Google Chrome ‘Paste and go’

Google Chrome Paste and goI already love all those nice little details in for example gmail but I just discovered a nice feature in Google Chrome. When you have an url on your clipboard that you want to paste in the address bar you just right click it and then this popup context menu appears.

 

There you have the ‘Paste and go’ option! I tried this in Firefox and Internet Explorer but not Safari and Opera but I think Chrome is the first with such an option.

Import/export by using DataSet WriteXml and ReadXml

I just tried to create a simpel import/export feature in one of our applications based on XML. My first thought was: Create a typed dataset and for export just serialize it to XML with the WriteXml method and for import deserialize it by using ReadXml.

Well the write part created exactly the file that I wanted but the ReadXml did not work as expected. No exceptions occured but no data was read so I could not add the data to the database. I remembered that I probably had to do with a schema option. Either at the write or the read. I wanted the write to behave like it was doing now. So browsing MSDN gave me the answer that I had to use the XmlReadMode.InferSchema parameter to the ReadXml method. That uses typed dataset information to check for data consistency.

So now my simple import/export is working again and it appears that my (typed) dataset knowledge was a bit rusted by not using it for quite a while.

  • Recent Posts
  • Recent Comments
  • Archives
  • Categories
  • Meta