I am trying to execute a query like the following, using HQL, that uses a native SQL function (dbms_lob.getlength
):
def results = Attachment.execute
In Attachment
domain add new field Long fileBytesLength
and inside mapping closure add the formula for calculating the length of fileBytes
field.
class Attachment {
String createUserName
String originalFilename
byte[] fileBytes
Long fileBytesLength
Date dateCreated
//Other Properties
static mapping = {
//Other mappings
fileLength formula: "dbms_lob.getlength(fileBytes)"
}
}
And then modify the query to:
def results = Attachment.executeQuery(
'select id, originalFilename, fileBytesLength, dateCreated, createUserName '+
'from Attachment a where a.id not in '+
'(select attachmentId from SpecVersion sv where sv.attachmentId is not null) '+
'and a.dateCreated > sysdate - 30')