Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Mixing InheritanceType.SINGLE_TABLE and InheritanceType.JOIN
PostPosted: Wed Nov 01, 2017 11:21 am 
Newbie

Joined: Wed Jan 24, 2007 9:23 am
Posts: 5
Location: London, W2
We have a third party entity inheritance structure where we are extending their CUSTOMER_CREDIT_ACCOUNT, this entity uses a inheritance strategy of InheritanceType.JOIN with it's superclass. We effectively want to subclass this entity (actually two subclasses) and ideally using the default discriminator column, which we have added by way of a SQL ALTER to CUSTOMER_CREDIT_ACCOUNT. These two subclasses will have an inheritance strategy of InheritanceType.SINGLE_TABLE with CUSTOMER_CREDIT_ACCOUNT.

This "structure" does not seem to work in an Oracle DB environment, at runtime I am getting:

Code:
ORA-00942: table or view does not exist


and beefing up the SQL logging I see that it does not seem to be resolving my subclass entity to it's table name, so the error fits!

Looking at this problem I almost want to be adding a InheritanceType.SINGLE_TABLE strategy to CUSTOMER_CREDIT_ACCOUNT in addition to the existing InheritanceType.JOIN (with it's superclass), almost like saying well we want JOINED upwards and SINGLE_TABLE downwards (from CUSTOMER_CREDIT_ACCOUNT), but this cannot be specified.

Without creating another table I do not see resolution -> extending CUSTOMER_CREDIT_ACCOUNT with an actual table, including the DTYPE and then subclassing, using this discriminator column to specify.

Any pointers or even solutions would be greatly appreciated!


Top
 Profile  
 
 Post subject: Re: Mixing InheritanceType.SINGLE_TABLE and InheritanceType.JOIN
PostPosted: Wed Nov 01, 2017 11:45 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1582
Location: Romania
Add the class diagrams or the database table EMR so that it's easier to understand what you have and what you ultimately want to have.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Mixing InheritanceType.SINGLE_TABLE and InheritanceType.JOIN
PostPosted: Wed Nov 01, 2017 2:06 pm 
Newbie

Joined: Wed Jan 24, 2007 9:23 am
Posts: 5
Location: London, W2
Not sure how I can add any sort of diagram so I have knocked one up in draw.io:

https://www.draw.io/?lightbox=1&highlight=0000ff&edit=_blank&layers=1&nav=1&title=Untitled%20Diagram.html#R7Vptb9s2EP41%2FthA73E%2Bxm6SZci6Yim29dNAS2eJCCUaFFXb%2FfU7SqQsiXLqBnESpDaQWDwe76h7Hh6Pkif%2BPN%2FcCLLK%2FuAJsInnJJuJ%2F3Hiea4XnuOXkmwbybnnNoJU0EQr7QT39DtooaOlFU2g7ClKzpmkq74w5kUBsezJiBB83Vdbctb3uiIpWIL7mDBb%2Bg9NZNZIp6Gzk%2F8GNM2MZ9fRPQsSP6SCV4X2N%2FH8Zf1punNibGn9MiMJX3dE%2FtXEnwvOZXOVb%2BbAVGxN2Jpx13t623kLKORBA85JvCDheTCF0L%2BIFh%2B0hW%2BEVToWS0Fy0LOVWxMhnPhKXVY5u64V%2FNk6oxLuVyRW8jUSA2WZzBm2XLysowLKr4Ot9sZVI%2BY5jfU1IwtgszaMc864wK6CF8pHKQV%2FACPE6Dr1p%2B0xaCmHS8pYR1PjgHJeyGuSU6bI%2BTeIhBREizUTXUe3xxwRRtMCZTGGGLBzZsfcBBGEhE1HpDG4AZ6DFFtU0b2GDtt%2Bc93hnpFlXd45kZYSTfi0Nb0DHS807gdywLjqkGAuIKHyMo4RE2mTYU1zRmqAOoDXAdVKNcoZZckd2fJKTb%2BUiLFpzTIu6HfUJ2YwdgsDhxcN0NRk2A26V8a0GwElDvts4HBb0R0pZUs4xsiqpIt6ckolJyKlxYxLyXNDUX1X13t49PKEfnvE9cM%2BcwPPYq4bjTHXfYS42ttfmNlJkSJEP%2BPuYsQbEqjnjDAMQEEkzBQipbVY2vt82vrxR9YPoxjk3ipyT8votIxM%2Fg%2F6vA6j51hHh24AfuBgzeb5bhjFYbSAkSJgXpWIKIjTPvBuCWyxdYTTB%2B8DYyXMOIGd97MRWOvIt9aRtWSgSC7VgQVbC8YVebtLBzZU%2Fqv4cxbq1lfNJsRFbDtdqvnVjCoSxdVW0xywXL8FGxLrAGSlr5JXIobHUwSuzhTMsPE60uZMB6RwBCQjE8CIpN%2F683yEJp85VTnJUCRw%2BxRxLwZMa%2B5Pj%2BqekYaGooGhYGCoCYJl6DkYFBxSSZzy8CkP78uLzikPw4fw%2Febh4FVTrHfRQ9%2BfTp%2BYYoeGvJdLsdEhKdYmzCnH%2Fqo5dlgPhOHFgTn2OIc1%2B2nDMbKb9xLpbe%2BjlG6d%2BcZy4ODoHgxBPjgH%2BoMc6L9cDnTtE%2F8xOHT%2BKltk9OYpZBVRT6VQMKDQC55UXO%2BnKKS3goSUWb2duH06HQr9a0HmDvYAf%2Fgi5lDIoukPDB0TMvv5xJeMiqQJtNzW3%2FGDelfqzdUKyqBUtb9ccwVOIamkUKq5CjAhBTW6KmmRKnmB%2F26LDATFg0MMZ7%2F%2Fefvp6mNNCoG66bYxTM%2FgbMTuvJVJglVLafEJ93DZ502%2FtNAkGymjTF3AYKksqHqAxoRdanFOk0Q5GX2n2a%2BBnqGgCAdk8qb2oc3zx45RR6kn7NNSUxCr2FeLmJFSYZ5REETE2bZBs4plJTRPEBVc6Q0F9jw4Vmq5%2BtlAzReueELwL6FlLGhO8SiIaKn3%2B6zK684kqTUl328T6VarZFXZY%2BNiq613mXh%2F%2B%2Bnm7uq%2FL5ezu6seH98pxcJwvErpUmzsFfMTKIbN3Q8Ymjy1%2B5WIf%2FU%2F


Top
 Profile  
 
 Post subject: Re: Mixing InheritanceType.SINGLE_TABLE and InheritanceType.JOIN
PostPosted: Thu Nov 02, 2017 3:47 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1582
Location: Romania
I tried it with this example on my book GitHub repository.

So, it doesn't matter if you declare JOINED further down the inheritance tree, Hibernate will still consider the root inheritance strategy, which is SINGLE_TABLE.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Mixing InheritanceType.SINGLE_TABLE and InheritanceType.JOIN
PostPosted: Fri Nov 03, 2017 11:30 am 
Newbie

Joined: Wed Jan 24, 2007 9:23 am
Posts: 5
Location: London, W2
I am really attempting the reverse (as in reverse strategies), if you would allow me to demonstrate. I, if you like, have Topic, Post and Announcement as three Hibernate entities, relating to three database tables, all related using an inheritance strategy of JOINED. Now, SMSAnnouncement and EmailAnnouncement are really types of Announcement, picture a discriminator column on the ANNOUNCEMENT table, with values of "SMS" and "EMAIL". When I try a

Code:
SELECT smsAnnouncement FROM com.mylib.SMSAnnouncement smsAnnouncement


Hibernate tries to resolve SMSAnnouncement to a table even though it has been declared with

Code:
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)


and so too, EmailAnnouncement.

I think Hibernate is honoring the strategy declared at the root, which is JOINED and therefore our SMSAnnouncement is trying to be resolved as a table and Oracle is well, not finding a table called 'SMSAnnouncement' by throwing a 'ORA-00942: table or view does not exist'

Does that make sense?


Top
 Profile  
 
 Post subject: Re: Mixing InheritanceType.SINGLE_TABLE and InheritanceType.JOIN
PostPosted: Fri Nov 03, 2017 11:35 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1582
Location: Romania
Yes, only the root mapping will be considered and you can't override it.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Mixing InheritanceType.SINGLE_TABLE and InheritanceType.JOIN
PostPosted: Fri Nov 03, 2017 12:52 pm 
Newbie

Joined: Wed Jan 24, 2007 9:23 am
Posts: 5
Location: London, W2
That is a shame. It's so clean and tidy having a discriminator column.

Thank you for your assistance.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.