Illep
Illep

Reputation: 16841

Increase limit of a VARCHAR in grails

In grails i have declared a variable in the Model called. String dnaSequence

I am trying to to save a huge long string into it and i get the following error message saying its too big.

How can i increase the limit to 900,000 or more ?

How can i achieve this?

Note: The solution given should be something that i can achieve with Grails.

My Domain class

class Animal {


    String dnaSequence

    static constraints = {

    }
}

Upvotes: 1

Views: 1847

Answers (3)

prabhatojha
prabhatojha

Reputation: 2085

You can use database mapping in your domain class

class Book {
    String name
    Status status

    static mapping = {
        delegate.name column: "name", sqlType: "text", length: 2000
    }
}

For more details https://docs.grails.org/latest/ref/Database%20Mapping/column.html

Upvotes: 0

Nathan Hughes
Nathan Hughes

Reputation: 96385

The max size of a VARCHAR is set in the database, Grails doesn't have any say in the matter. What you can do is tell Grails what you need, and it will generate DDL that uses a clob instead of a string.

Change the mapping for the column to use type: "text", while adding the maxSize you want in your constraints. Grails will figure out from this that it should set the column data type to clob.

(Generally a clob field will hold up to 4GB, though some databases allow changing that.)

Upvotes: 3

rmlan
rmlan

Reputation: 4657

You might be interested in the type mapping in GORM. Specifically, you could add this to change the type of the dnaSequence field:

static mapping = {
    dnaSequence type: "text"
}

Upvotes: 1

Related Questions