Hello Adrien Comments inline:
2014-12-16 15:52 GMT+01:00 <[email protected]>: > Hi. > > I'm new to JOOQ, and I have to admit I'm looking for "the right way to use > it". > Here are a couple of questions: > > 1. Is inheriting from a Record class a good idea? > > Let's say I have a table A with an id field. > Without JOOQ, I would probably have something like: > > class A { > private int id; > public void setId(...) { ... } > public int getId() { ... } > > // additional behaviour > } > > With JOOQ, I feel I should do: > What makes you feel this way? > > class A extends ARecord { > // additional behaviour > } > > Does that seems to be ok? > You could do that, of course, but then your "POJO" wouldn't be a POJO but a Record with all strings attached. You could also activate POJO generation in jOOQ and use jOOQ's DefaultRecordMapper to map Records to POJOs: - http://www.jooq.org/doc/latest/manual/code-generation/codegen-pojos/ - http://www.jooq.org/doc/latest/manual/sql-execution/fetching/pojos/ > Another way to do it would be: > > class A { > private ARecord aRecord; > public void setId(int id) { aRecord.setId(id); } > public int getId() { return aRecord.getId(); } > > // additional behaviour > } > > But that feels cumbersome to me. > Yes. And why would you do it? Why not just pass around the record directly? > 2. Same question, but including PostgreSQL inheritance feature > > As of now, I have 3 tables: > - parent > - childA inherits from parent > - childB inherits from parent > > My Java objects are reflecting that tree : > > class Parent { ... } > class childA extends parent { ... } > class childB extends parent { ... } > > If I understand correctly, JOOQ does not handle PostgreSQL inheritance yet. > Not yet: https://github.com/jOOQ/jOOQ/issues/2777 It's not a priority yet, as few people really use Informix / Oracle / PostgreSQL's ORDBMS features this way. Once you've set up inheritance in your database, the DDL for database migrations becomes extremely difficult. In jOOQ, the problem that we haven't solved yet when records participate in such inheritance structures has to do with generics. We've gotten 1-2 things "wrong" in the early days of jOOQ which keeps us from finding a solid solution to mapping table inheritance from the database to class inheritance in Java. Some details can be found in this blog post: http://blog.jooq.org/2013/06/28/the-dangers-of-correlating-subtype-polymorphism-with-generic-polymorphism/ > So, I do not find a clean way to use these table. Of course, the Java > children reuse some Parent behaviour. > What do you want to do? -- You received this message because you are subscribed to the Google Groups "jOOQ User Group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
