Parameterized Queries in HQL
NHibernate supports parameterized queries but unless you go looking in the Java documentation it’s not obvious how to do it. Turns out it’s really simple:
IList results = _session.Find(“from MyAssembly.MyClass as MyClass where MyClass.Foo = ?”,
tagText, TypeFactory.GetStringType(64));
You can pass in arrays of objects and types for the last two parameters if you have more than one parameter in your HQL.
January 16th, 2006 at 3:26 pm
You can also use named parameters (which I find very useful) using:
“from MyAssembly.MyClass as MyClass where MyClass.Foo = :fooVal”