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?