Informix table creation error [message #893273] |
Tue, 03 July 2012 12:37 |
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?
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02317 seconds