0

This question is similar to this post – but the answer does not apply here. I am currently only working in development and configured as dbCreate: create-drop with url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE

Using Grails 3.0.11 – GORM seems to not recognize type:'text' mapping. Here is my model:

package mypackage

class Text extends Object {

    String body
    Media image

    boolean textFirst = true

    static constraints = {
        image nullable:true
    }

    static mapping = {
        body type: 'text'
    }
}

Bootstrapping some data, I'm being thrown this error:

ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Value too long for column "BODY VARCHAR(255)": "'<p>some copy... (1222)"; SQL statement:
insert into object (id, date_created, description, heading, last_updated, title, two_col, body, image_id, text_first, class) values (null, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'mypackage.Text')

My understanding is that the mapping to type:text should create CLOB-type variable, which is automatically not constrained to max size 255.


Attempted Solutions

  1. grails clean - application is cleaned, no success
  2. grails clean-all - this isn't a Grails 3+ method (does not work)
  3. grails clean --refresh-dependencies – cleans, but no success
  4. Swapped the order of static constraints and static mapping in the model, no success
  5. Added body maxSize: 5000 to my model constraints , no success
  6. grails url-mappings-report strangely completes the Bootstrap without throwing an error.


Edit 1

This might have to do with inheritance – the Text Class currently extends Object. Changing the Text model as follows, Bootstrapping succeeds. Could anyone provide me with some insight?

package mypackage

class Text {

    String body
    Media image

    boolean textFirst = true


    static constraints = {
        image nullable:true
    }

    static mapping = {
        body type: 'text'

    }
}

This is the mypackage.Object:

package mypackage

class Object {

    String title
    String heading
    String description

    Date dateCreated
    Date lastUpdated

    boolean twoCol = false

    static constraints = {
        heading nullable: true, maxSize: 3000
        description nullable: true, maxSize: 500
    }

    static mapping = {
        version false
    }
}


Edit 2

Renamed the body container to content, grails clean and it seems to be working now. Still unsure of what was going on, maybe some sort of caching issue (?) ...

Any help is awesome!! Thank you all :)

2 Answers2

0

Please try this

static mapping = {
        body sqlType: 'text'
    }
elixir
  • 1,394
  • 1
  • 11
  • 21
  • No success – same error is being thrown. Even after cleaning the app. Thank you – Vessy Stroumsky Jul 18 '17 at 15:58
  • every class in java/groovy extends Object class by default. You should rename the class to something else. Also check if "text" is not the reserved word for the database you are using. – elixir Jul 18 '17 at 17:04
  • I tried to rename the Object class and wasn't able to get the program running. Renamed `body` to `content` and it seems to be working now. Thanks for your help! – Vessy Stroumsky Jul 18 '17 at 20:03
-1

Please try this

static mapping = { body type: 'text' }

rupi
  • 3
  • 3