streetmaster86
streetmaster86

Reputation: 67

JOOQ - Why does my DAO store empty datasets?

i hope anybody can help me. First of all, I'm a newby in using JOOQ. I've created some Java-Classes wie the codegen tool.

I can load existing Records from database already, e.g.

AddressDao dao = new AddressDao(context.configuration());
Address address = dao.findById(1);

But when i change some values and calling update, the record in database stays unchanged.

address.setName("Test");
dao.update(address);

When i'm creating a new Record, a new record in database will be created, but it is empty.

Address address = new Address();
address.setName("test");
dao.insert(address);

What am i doing wrong?

Upvotes: 1

Views: 71

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 221135

As per the comments, if you implement your own custom GeneratorStrategy you will still need to make sure to adhere to the rules specified by the DefaultRecordMapper for the DefaultRecordMapper to work.

The DefaultRecordMapper is reflection based, so it tries to match source record field names with target POJO attribute names by certain conventions. If you, for example, prefix all your attributes with FOO, then jOOQ can't simply match a COLUMN to a fooColumn attribute!

You can override the default with a DefaultRecordMapperProvider, but that's a lot of work for something that would otherwise work out of the box.

Now, in the special case of generated DAO types, arguably, this is a bug, because the DAO::mapper method has been added specifically to override the default behaviour. Perhaps, generated DAO should implement a custom RecordMapper that is capable of mapping between records and your custom named POJOs. I've created an issue for this:

Irrespective of this DAO related bug, just be aware that in general, the DefaultRecordMapper is unaware of your GeneratorStrategy

Upvotes: 0

Related Questions