Java – can I select null as the column value in the HQL query?
•
Java
I need a list of three columns Columns 1 and 3 have values, while column 2 is empty
I need something like this:
select id,null,name from MyClass
MyClass and the underlying table have only two attributes / columns, "Id" and "name"
Solution
Another option that seems to work (tested on DB2, mysql, Oracle, and SQL Server):
select id,cast(null as char),name from ...
You can subclass hibernate dialect and abstract it with custom functions:
registerFunction("always_null",new sqlFunctionTemplate(Hibernate.STRING,"cast(null as char)"));
Then use it in your HQL:
select id,always_null(),name from ...
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码