Error 'No such field <ID>' on H2 database
Running SampleCode test on H2 database generates the following error
No such field: ID
in the call
List<Name> list = db.where("firstName=?", "John").results(Name.class);
The problem is, that H2 follows strong the ANSI definition, that unquoted column names are returned in the metadata queries in uppercase. I found discussions with the H2 author regarding metadata format here and here.
The workaround is
- Annotate each column with uppercase name
@Id
@GeneratedValue
@Column(name="ID")
public long id;
- For H2 you can use specific JDBC URL option
database_to_upper=false. However, the database must be dropped and re-created, the workaround does not work on existing DB.
I do not know if I should classify this as a bug, anyway, the current behavior is not ANSI conform. On the other side, ANSI metadata handling probably breaks MySql or Postgres API.
No idea where to start to hunt the bug., but IMO it should be solved.
Robert
I'm open to suggestions on how to fix.