Grails

ApplicationBootStrap creation of a record that contains a URL greater than 100 characters causes SQL error Data truncation

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Won't Fix
  • Affects Version/s: 1.0
  • Fix Version/s: 1.0.2
  • Component/s: None
  • Labels:
    None
  • Environment:
    Windows Server 2003 - JDK 1.5.0_13 with MySQL Connector 5.1.5

Description

In my test system I create a record and I include a URL to another site.

In this case I use:

new Book(title: "Grails",
url: new URL("http://www.amazon.co.uk/s/ref=nb_ss_w_h_?url=search-alias%3Dstripbooks&Go.x=5&Go.y=15&field-keywords=Grails"),
).save()

When I run it I get the following error:

2008-02-21 16:47:18.920::WARN: Failed startup of context org.mortbay.jetty.webapp.WebAppContext@7c4246{/URLTest,C:\steve\URLTest/web-app}
org.codehaus.groovy.runtime.InvokerInvocationException: org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not insert: [User]; uncategorized SQLException for SQL [insert into user (version, email, first_name, last_name, password, url) values (?, ?, ?, ?, ?, ?)]; SQL state [01004]; error code [0]; Data truncation: Data too long for column 'url' at row 1; nested exception
is com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'url' at row 1

If I reduce the size of the URL to be below 100 characters it works fine. In the MySQL database the field is of type "tinyblob".

Activity

Hide
Graeme Rocher added a comment -

You can change the hibernate type with:

static mapping = {
     url type:"blob"
}

or

static mapping = {
     url type:"text"
}
Show
Graeme Rocher added a comment - You can change the hibernate type with:
static mapping = {
     url type:"blob"
}
or
static mapping = {
     url type:"text"
}
Hide
Jürgen Jatzkowski added a comment -

Following the suggested mapping (grails 1.0.2) I get a class cast exception (type: "blob") while type:"text" seems to work.

2008-04-02 23:45:06,387 ERROR [ExceptionPrinterJobListener] Exception occured in job: GRAILS_JOBS.TestJob
org.quartz.JobExecutionException: Invocation of method 'execute' on target class [class TestJob] failed [See nested exception: java.lang.ClassCastException: java.lang.String]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:83)
at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:283)
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86)
at org.quartz.core.JobRunShell.run(JobRunShell.java:203)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)

  • Nested Exception (Underlying Cause) ---------------
    java.lang.ClassCastException: java.lang.String
    at org.hibernate.type.BlobType.set(BlobType.java:49)
    at org.hibernate.type.BlobType.nullSafeSet(BlobType.java:117)
Show
Jürgen Jatzkowski added a comment - Following the suggested mapping (grails 1.0.2) I get a class cast exception (type: "blob") while type:"text" seems to work. 2008-04-02 23:45:06,387 ERROR [ExceptionPrinterJobListener] Exception occured in job: GRAILS_JOBS.TestJob org.quartz.JobExecutionException: Invocation of method 'execute' on target class [class TestJob] failed [See nested exception: java.lang.ClassCastException: java.lang.String] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:494) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:83) at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:283) at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86) at org.quartz.core.JobRunShell.run(JobRunShell.java:203) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
  • Nested Exception (Underlying Cause) --------------- java.lang.ClassCastException: java.lang.String at org.hibernate.type.BlobType.set(BlobType.java:49) at org.hibernate.type.BlobType.nullSafeSet(BlobType.java:117)

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: