Sigh, I had a whole set of inline responses written out, but Google didn't 
post them and I've lost the message.  Anyway, summary of what I just wrote:

   - Lukas, thanks as always for your response
   - I hadn't considered writing a custom generator.  The only snag here is 
   that we add annotations to certain methods depending on how we want these 
   POJOs concerted to JSON.  Will look into this; a cool idea toward 
   automating!
   - Regarding PostgreSQL inheritance, I was initially excited about this, 
   but I was scared off by many of the limitations and edge cases that we will 
   inevitably run into.  For example, foreign key relationships get inherited 
   but the relationship itself doesn't appear to be enforced in a child table. 
    Do you have jOOQ customers using Oracle or Postgres inheritance with 
   success?  Do you see this as a strong option for supporting inheritance in 
   jOOQ or just one option?

Thanks again for your input!

Josh

On Wednesday, September 3, 2014 7:37:15 AM UTC-7, Lukas Eder wrote:
>
> Hello Josh,
>
> 2014-09-02 21:18 GMT+02:00 Josh Padnick <[email protected] <javascript:>
> >:
>
>> Hello,
>>
>> First, been really enjoying jOOQ. What a pleasure to use and have the 
>> full power of SQL available.  Ok, so my question is about modeling 
>> inheritance with jOOQ.
>>
>> I've reviewed the history of posts on this and come across:
>>
>>    - https://groups.google.com/d/msg/jooq-user/9dfbLtnR77c/_0GL1H7f2ZYJ 
>>    - https://groups.google.com/d/msg/jooq-user/FLrkH_u2bbE/zJS8DQeFu2wJ
>>    - https://groups.google.com/d/msg/jooq-user/9X_0gROVIf8/XZc2OXqitJQJ 
>>    - https://groups.google.com/d/msg/jooq-user/YuTp9-5K9fs/_d5siyYQn3EJ 
>>    
>> I understand (and agree) with Lukas's position that since SQL does not 
>> directly model inheritance, jOOQ should not either.  I'd like to describe 
>> my approach to working around this and would appreciate any feedback for 
>> better ways of handling this.
>>
>
> Hmm, that's not 100% my position. SQL (or at least ORDBMS like Oracle and 
> PostgreSQL) does support inheritance. So far, this kind of true ORDBMS 
> table inheritance has been a low priority for jOOQ, though, as it is hardly 
> ever used.
>
> As far as various models of mapping Java inheritance to SQL through 
> discriminators, joins, etc. is concerned, I'm indeed a bit reluctant as 
> jOOQ does not implement this kind of ORM.
>  
>
>> *SQL*
>> We have the following tables:
>>
>> CREATE TABLE notify_event (
>>     notify_event_id SERIAL  NOT NULL,
>>     PRIMARY KEY (notify_event_id),
>> );
>>
>>
>> CREATE TABLE notify_event_text_message (
>>     notify_event_id INTEGER  NOT NULL,
>>     message_body TEXT  NOT NULL,
>>     CONSTRAINT PK_notify_event_text_message PRIMARY KEY (notify_event_id)
>> );
>>
>> Basically, a notify_event is the parent type, and 
>> notify_event_text_message is the subtype.
>>
>> *Object Model*
>> In Java, we have modeled this as follows:
>>
>>    - class NotifyEvent extends generated.tables.pojos.NotifyEvent 
>>    - class NotifyEventTextMessage extends NotifyEvent
>>
>> We're using a POJO pattern where we define our own POJOs, but just extend 
>> from the jOOQ auto-generated POJO in most cases and then add in any 
>> customizations we want.  This has worked very nicely so far, particularly 
>> for converting to/from JSON with the opportunity to customize the JSON 
>> serialization.
>>
>> It even works well with patterns like:
>>
>> notifyEventTextMessageRecord.into( models.NotifyEventTextMessage.class )
>>
>> And then I manually manage the POJO member property links.  
>>
>> *My Questions*
>> Does anyone else use this pattern with success?  Are there unforeseen 
>> issues we may run into down the line?  
>>
>> So far, it's worked very well, with the sole exception that we have to 
>> copy & paste the jOOQ auto-generated POJO into any subtypes (e.g. 
>> NotifyEventTextMessage above) because Java doesn't like multiple 
>> inheritance.
>>
>
> You might be able to implement that copy & pasting also when overriding 
> the code generator behaviour... Have you tried that?
>
> Apart from that, given that you're using PostgreSQL, you may in fact try 
> to use PostgreSQL's inheritance mechanism. This will be transparent to 
> jOOQ, and jOOQ will generate NotifyEventTextMessage POJOs with all 
> inherited columns as well.
>
> More information here:
> http://www.postgresql.org/docs/9.3/static/tutorial-inheritance.html
>
> Cheers
> Lukas
>

-- 
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.

Reply via email to