How to create file upload in grails that works with oracle?

The following problem occurred:

I tried to create a simpel file upload function in grails. I just created a domain class with

byte[] rawFile

as a property. For me, Grails left everything else for me. It worked fine for the standard hsqldb in dev environment.

Then I deployed it to the server with oracle db (thin driver) installed. Everything except file uploads works great with oracle db. To download the file I get (as far as I remember)

SQLException: ORA-01461: can bind LONG value only for insertion into LONG

I tried several ways to fix it (including some collation of columns with blocks and using java.sql.blob instead of byte []), but nothing really worked, and I went in the direction where my code would no longer be db.

Google really didn't help me, and my books about the Grail don't help either.

Saving a file to disk is not a good solution. My opinion.

So here is my question:

How to create file upload in grails that works with oracle?

Update : additional information has appeared. I managed to reproduce the problem with the XE version of Oracle:

Hibernate creates a VARBINARY (255) column for rawFile. So I tried to upload a file of 4 bytes in size, and it worked.

Then I manually changed the column type to "blob" and worked with large files.

Then i added

static mapping = {
    columns {
        rawFile type:'blob'
    }
}

for my domain class and it stops working:

Errors ERROR.GrailsExceptionResolver - [B cannot be added to java.sql.Blob java.lang.ClassCastException: [B cannot be added to java.sql.Blob

: - (

+5
4

blob maxSize:

static constraints = {
    rawFile(maxSize: 20 * 1024 * 1024) // 20 MBs
    // ...
}
+4

Blob Oracle, [] org.hibernate.type.MaterializedBlobType. MaterializedBlobType Oracle ( , Oracle) [].

byte[] blobFile

static mapping = {
    blobFile type: org.hibernate.type.MaterializedBlobType
}
+4

, , , , :

request.fileMap.each { name, file ->
    if (!file.empty) {
        model.rawFile = file.bytes
    }
}
model.save()
+1

sqlType.

byte[] sqlType, "blob" mapping, Grails 2.3.1 Oracle 11g. Grails .

class Image {
    byte[] image
    static mapping = {
        image(sqlType: "blob")
    }
}
+1

All Articles