I am using DataNucleus’s implementation of JDO on an H2 database instance opened in MySQL mode.
I need to create items made of three strings in a table. The last string can be of any length. I have created the following object which persists fine, except for values larger than 256 characters. DataNucleus automatically set the size limit to 256:
@PersistenceCapable(objectIdClass=RawItemKey.class)
@Index(name="BEGIN_IDX", members={"prefix", "language", "value"})
public class RawBeginItem {
@PrimaryKey
@Column(length=40)
private String prefix = "";
@PrimaryKey
@Column(length=2)
private String language = "";
@PrimaryKey
@Column(jdbcType="VARCHAR")
private String value = "";
public RawBeginItem() {
}
public RawBeginItem(String prefix, String language, String value) {
this.prefix = prefix;
this.language = language;
this.value = value;
}
...
}
How can I tell JDO that the 3rd field is a String of any length? Which SQL type should I use? How should I declare it? Thanks.
VARCHAR column types of unspecified length is not compatible with SQL standard. JDO expects that one is set. H2 seems to allow you not too specify one, but it appears it does default to max signed int, so @Column(length=Integer.MAX_VALUE) would be the correct mapping imho.