Statically defined List is not recognized by jOOQ in Repository class

We’ve got a pattern that has worked in the past for insert statements, but I’m attempting to reuse it for a select statement and seeing what I’d consider to be unexpected behavior. Assume everything that isn’t delineated here is correctly defined; I’m trying to keep this brief, not cover the nitty-gritty details.

So I have an entity (all code is Groovy):

class SomeEntity {
    
    static class COLUMNS {
        public static final String COL_1 = 'col_1'
        public static final String COL_2 = 'col_2'
        // ...elided
    }

    static class FIELDS {
        public static final Field<String> COL_1 = DSL.field(COLUMNS.COL_1, String)
        public static final Field<String> COL_2 = DSL.field(COLUMNS.COL_2, String)
        // ...elided
    }

    static List<Field<?>> ENTITY_FIELDS = [FIELDS.COL_1, FIELDS.COL_2]

    @Column(name = COLUMNS.COL_1)
    String col1

    @Column(name = COLUMNS.COL_2)
    String col2
}

(This is severely truncated as a minimal example. There are also Boolean, LocalDateTime, and BigDecimal Fields.)

And then a repo like this:

@Repository
class SomeEntityRepo {

    DSLContext jooq

    SomeEntityRepo(DSLContext jooq) {
        this.jooq = jooq
    }

    SomeEntity findEntityDate(String id) {
        return jooq.select(ENTITY_FIELDS)
                   .from(table)
                   .where(COL_1.eq(id))
                   .fetchOneInto(SomeEntity)
    }

}

(also truncated, we use constructor injection… there’s a join that will happen, etc.)

What I’m seeing is that jOOQ is executing a select * from ... rather than a select col_1, col_2 from .... The minute I move the declaration of ENTITY_FIELDS into the repository class, it works as expected.

The main issue here is that this should actually end up as select table.col_1, table.col_2 from ... because there’s a join and, of course, both tables have an id column. I can, of course, define the List<Field> in the repo class, but I have more than one such list, so it’s kind of nice to have them declared (and hidden away) in the entity classes. Also, there’s another query that’s more join-heavy and ultimate what got me hunting down this issue.

Again, using these entity-defined Lists works just fine for insert statements, so I’m confused why they are not recognized correctly by the select. I’ve read the documentation and noticed that * is substituted when columns are not recognized, but I’ve even gone so far as to reduce the entity-defined List to just the ID field and it still does a select *.

Am I missing something? Is there a reason for this? Is the behavior caused by jOOQ or is this a Spring issue? This project is using Spring Boot 3.2.2 and jOOQ 3.17.6.


P.S. Update:

I’ve continued to mess around here and think I may have found a reason for this, but it also boggles my mind. The SomeEntity class also has this going on:

class SomeEntity {

    public static final String TABLE_NAME = 'table_name'
    public static final org.jooq.Table ENTITY_TABLE = DSl.table(TABLE_NAME)

    public static final org.jooq.Table OTHER_TABLE = DSL.table('other_table')
    // and two more for other entities

    static class FIELDS {
        // previous entries elided
        public static final Field<String> OTHER_ID = DSL.field("$ENTITY_TABLE.other_id") // this is not exactly right, but gives the general idea of what we do in many places
        // repeat for a handful of other fields.
    }
}

If I move those additional entries to the repo class, everything suddenly works as expected (with the ENTITY_FIELDS list in-use). I can leave the “additional Tables” and it’s fine. If I also move the additional tables, it starts doing select * again.

I’m going to continue to experiment; these additional tables/fields technically don’t belong in SomeEntity, so I’ll see if refactoring them, together, works, but I’m not hold my breath given the above information.

9

This appears to have been due to some random relation/interaction that jOOQ had with a Map field in the repo class. Originally, I added it as a bit of a shortcut because it somehow allowed jOOQ to correctly assign properties in the .fetchOneInto(ResultObject) bit.

This was, of course, in an effort to remove the need to implement a fully-defined RecordMapper.map method. Being that this “result object” has ~111 properties, I really didn’t want to have to define every single one…

So, the “shortcut” map was as simple as this:

Map<String, Object> someRandomName = [
    (FIELDS.COL_1): 'col_1',
    (FIELDS.COL_A): 'col_a'
]

Where FIELDS.COL_A is defined on a subclass of SomeEntity. Nothing else was necessary for some “magic” to happen, but as a result of that magic, the ENTITY_FIELDS List suddenly contained only null elements.

What’s interesting is that the mere existence of this map seems to cause the issue, even when it’s not used, even when the proper RecordMapper.map method is implemented. Even more intriguing is that I can comment COL_1‘s mapping out and its list is then non-null, but the COL_A class’s list remains null-populated, and vice versa.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật