I need a list with three columns. column 1st and 3rd having values while 2nd as null. Can I do it through HQL query?
I need something like this:
select id, null, name from MyClass
Where MyClass as well as underlying table has only two properties/columns ie, "id" and "name"
You can use nullif()
function to generate null.
It accepts two arguments. If arguments are equal, it'll return null
value.
Another option that seems to work (tested on DB2, MySQL, Oracle, and SQL Server):
select id, cast(null as char), name from ...
You could subclass the Hibernate dialect and abstract it with a custom function:
registerFunction("always_null",
new SQLFunctionTemplate(Hibernate.STRING, "cast(null as char)"));
and then use this in your HQL:
select id, always_null(), name from ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With