Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Informix table creation error(Internal Exception: java.sql.SQLException: Maximum varchar size has been exceeded.)
Informix table creation error [message #893273] Tue, 03 July 2012 12:37 Go to next message
Jonathan Lister is currently offline Jonathan Lister
Messages: 2
Registered: July 2012
Junior Member
Compared to other database vendors the upper limit of a varchar for Informix is rather small at 255 bytes (cf. 2,000 bytes for postgresql or 4,000 for Oracle).

I would like my entity classes to work across multiple different database vendors, and hoped that when creating tables eclipselink would look at the length attribute and use that information to make an appropriate column type selection from either varchar, lvarchar or text.

This example entity class illustrates the problem:
@Entity
public class MyEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    private Long id;
    
    // a plain String without any size constraints
    private String plainString;
    
    // a String limited to a max. length of 32
    @Column(length = 32)
    private String stringSize32;

    // a String limited to a max. length of 128
    @Column(length = 128)
    private String stringSize128;

    // note that Informix has an upper limit of 255 for varchar 
    // a String limited to a max. length of 256
    @Column(length = 256)
    private String stringSize256;

    // a String annotated with @Lob
    @Lob
    private String lobString;



and here is the error message I get when using create-table:
[EL Info]: 2012-07-03 13:27:20.48--ServerSession(398388903)--EclipseLink, version: Eclipse Persistence Services - 2.3.2.v20111125-r10461
[EL Info]: 2012-07-03 13:27:22.876--ServerSession(398388903)--file:/C:/Users/pjl.VADOM/Documents/NetBeansProjects/test/test-informix-strings/target/classes/_TEST_PU login successful
[EL Warning]: 2012-07-03 13:27:22.993--ServerSession(398388903)--Exception 

[EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Maximum varchar size has been exceeded.
Error Code: -650

Call: CREATE TABLE MYENTITY (ID NUMERIC(19) NOT NULL, LOBSTRING TEXT, PLAINSTRING VARCHAR(255), STRINGSIZE128 VARCHAR(128), STRINGSIZE256 VARCHAR(256), STRINGSIZE32 VARCHAR(32), PRIMARY KEY (ID))

Query: DataModifyQuery(sql="CREATE TABLE MYENTITY (ID NUMERIC(19) NOT NULL, LOBSTRING TEXT, PLAINSTRING VARCHAR(255), STRINGSIZE128 VARCHAR(128), STRINGSIZE256 VARCHAR(256), STRINGSIZE32 VARCHAR(32), PRIMARY KEY (ID))")

[EL Info]: 2012-07-03 13:27:23.107--ServerSession(398388903)--file:/C:/Users/pjl.VADOM/Documents/NetBeansProjects/test/test-informix-strings/target/classes/_TEST_PU logout successful


Eclipselink tries to use an invalid column definition "VARCHAR(256)", but on the other hand it does seem to know that the upper limit is 255 because the plainString column has "VARCHAR(255)".

I realise that I could enforce a particular column type by using e.g. @Column(columnDefinition = " xx"), but I really want to be able to support multiple database vendors from the same set of entity classes and hoped that eclipselink would provide this flexibility.

Am I missing something obvious?

Re: Informix table creation error [message #893475 is a reply to message #893273] Wed, 04 July 2012 09:44 Go to previous messageGo to next message
Jonathan Lister is currently offline Jonathan Lister
Messages: 2
Registered: July 2012
Junior Member
It seems that OpenJPA had a similar problem: (can't enter URL until I have posted > 25 messages) paste this into your browser and pre-pend http://

openjpa.208410.n2.nabble.com/jira-Created-OPENJPA-1420-Long-strings-are-improperly-mapped-on-Informix-td4133664.html
Re: Informix table creation error [message #893528 is a reply to message #893475] Wed, 04 July 2012 13:05 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You could define your own InformixPlatform subclass, and use a different type for String it its fieldMappings.

James : Wiki : Book : Blog : Twitter
Previous Topic:How to prevent EL from creating Reference ReadAllQuery
Next Topic:Problems with @Id in mapped superclasses
Goto Forum:
  


Current Time: Tue Sep 30 21:55:18 GMT 2014

Powered by FUDForum. Page generated in 0.01924 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software