Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this value too long for my H2 table

I have a spring-data-jpa app that is using H2 for storage. When I try and parse some data into the table, I get an error:

 o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 22001, SQLState: 22001
2014-06-13 15:42:07.062 ERROR 66742 --- [nio-9001-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : Value too long for column "REMARKS VARCHAR(255)": "'""DOB 31 Jan 1939; Cedula No. 6068015 (Colombia); alt. Cedula No. 6067015 (Colombia); Passport T321642 (Colombia); alt. Passport... (259)"; SQL statement:
insert into sdn (call_sign, grt, program, remarks, sdn_num, sdn_type, title, tonnage, vess_flag, vess_owner, vess_type, ent_num) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [22001-172]

I have a table defined as:

CREATE TABLE IF NOT EXISTS Sdn (
  entNum    BIGINT (11) NOT NULL,
  sdnName   VARCHAR(700)  NULL,
  sdnType   VARCHAR(24)   NULL,
  program   VARCHAR(100)  NULL,
  title     VARCHAR(4000) NULL,
  callSign  VARCHAR(20)   NULL,
  vessType  VARCHAR(50)   NULL,
  tonnage   VARCHAR(30)   NULL,
  grt       VARCHAR(20)   NULL,
  vessFlag  VARCHAR(80)   NULL,
  vessOwner VARCHAR(300)  NULL,
  remarks   CLOB          NULL,
  UNIQUE KEY entityNum(entNum)
);

And my @Entity class as:

@Entity
public class Sdn {

    @Id
    private long entNum;
    private String sdnName;
    private String sdnType;
    private String program;
    private String title;
    private String callSign;
    private String vessType;
    private String tonnage;
    private String grt;
    private String vessFlag;
    private String vessOwner;
    private String remarks;

Here is the offending record, which is clearly small enough to fit into the column:

"DOB 31 Jan 1939; Cedula No. 9876543 (cccccccc); alt. Cedula No. 6067015 (cccccccc); Passport T123456 (cccccccc); alt. Passport 1234567 (Comoros); alt. Passport 12345 (Argentina); alt. Passport 87654321 (ppppppppp); a.k.a. 'THE TTTT PLAYER'; a.k.a. 'NAME1'."

All I can think is that the semicolins or some other invalid character is throwing this exception.

Can anyone see the problem here, and suggest an alternative to handling it?

like image 898
sonoerin Avatar asked Jun 13 '14 21:06

sonoerin


1 Answers

Your stated table definition:

CREATE TABLE IF NOT EXISTS Sdn (
  entNum    BIGINT (11) NOT NULL,
  sdnName   VARCHAR(700)  NULL,
  sdnType   VARCHAR(24)   NULL,
  program   VARCHAR(100)  NULL,
  title     VARCHAR(4000) NULL,
  callSign  VARCHAR(20)   NULL,
  vessType  VARCHAR(50)   NULL,
  tonnage   VARCHAR(30)   NULL,
  grt       VARCHAR(20)   NULL,
  vessFlag  VARCHAR(80)   NULL,
  vessOwner VARCHAR(300)  NULL,
  remarks   CLOB          NULL,
  UNIQUE KEY entityNum(entNum)
);

does not agree with the error message, which says that the remarks column is VARCHAR(255) rather than CLOB.

And your value does exceed the 255 character limit.

You may need to alter the table to match what you thought it was.

Your entity appears to have no JPA or Hibernate annotations defining the types of your columns. You may also need to add an annotation on the remarks field identifying it as a CLOB.

like image 175
Don Roby Avatar answered Oct 31 '22 17:10

Don Roby