1

I'm using Fanbatis framework to access a MySQL database. The documentation here: http://www.talesframework.org/fanbatis/ says that I can use the @Column annotation to map a class attribute to a column with a different name:

@Column{name="xx"} - By default column name is assumed to be the field name, 
                     to change this use this annotation on a field 

I have this class...

using fanbatis

@Table {name = "APPS"}
class App
{
  @Primary 
  Str? id
  Str? name
  @Column{name="description"}
  Str? descr
}

And the APPS table created with this SQL:

create table APPS (
    ID              varchar(36)     not null,
    NAME            varchar(100)    not null,
    DESCRIPTION     varchar(400)    ,
    primary key (ID)
);

And I'm trying to retrieve a record from the database using this DAO

class AppDao
{
  static App? findById(Str id)
  {
    S<|
      select * from apps where id = #{id}
    |>
  }
}

My code compiles fine, but when I run it, passing in the ID of an existing record, it retrieves the record from the database and set the values of the attributes that match the column names, but the app.descr remains null. However, if I just remove the @Column annotation from the "descr" attribute and rename it to match the column ("description"), then the code runs fine and returns the expected values.

-- Run:  auth::TestAppDao.testFindById...
Test setup!
app.id: 0615a6cb-7bda-cc40-a274-00130281bd51
app.name: MyApp
app.descr: null

TEST FAILED
sys::TestErr: Test failed: null != "MyApp descr" [sys::Str]
  fan.sys.Test.err (Test.java:206)
  fan.sys.Test.fail (Test.java:198)
  fan.sys.Test.verifyEq (Test.java:121)
  fan.sys.Test.verifyEq (Test.java:90)
  auth::TestAppDao.testFindById (TestAppDao.fan:36)
  java.lang.reflect.Method.invoke (Unknown)
  fan.sys.Method.invoke (Method.java:559)
  fan.sys.Method$MethodFunc.callList (Method.java:204)
  fan.sys.Method.callList (Method.java:138)
  fanx.tools.Fant.runTest (Fant.java:191)
  fanx.tools.Fant.test (Fant.java:110)
  fanx.tools.Fant.test (Fant.java:32)
  fanx.tools.Fant.run (Fant.java:284)
  fanx.tools.Fant.main (Fant.java:327)
Test teardown!

Am I doing something wrong or is this a bug in Fanbatis?

LightDye
  • 1,234
  • 11
  • 15

1 Answers1

1

It could be due to case sensitivity - see MySQL 9.2.2. Identifier Case Sensitivity

Although database and table names are not case sensitive on some platforms, you should not refer to a given database or table using different cases within the same statement. The following statement would not work because it refers to a table both as my_table and as MY_TABLE:

mysql> SELECT * FROM my_table WHERE MY_TABLE.col=1;

Try:

@Column{name="DESCRIPTION"}

It's also mentioned in this question.

Community
  • 1
  • 1
Steve Eynon
  • 4,979
  • 2
  • 30
  • 48