norm icon indicating copy to clipboard operation
norm copied to clipboard

Error 'No such field <ID>' on H2 database

Open envas opened this issue 8 years ago • 1 comments

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

  1. Annotate each column with uppercase name
 @Id
 @GeneratedValue 
 @Column(name="ID")
 public long id;  
  1. 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

envas avatar Mar 01 '17 15:03 envas

I'm open to suggestions on how to fix.

ccleve avatar Mar 01 '17 17:03 ccleve