4

I am working on a new project using spring data jdbc because it is very easy to handle and indeed splendid.

In my scenario i have three (maybe more in the future) types of projects. So my domain model could be easily modelled with plain old java objects using type inheritance.

First question:

  • As i am using spring data jdbc, is this way (inheritance) even supported like it is in JPA?

Second question - as addition to the first one:

  • I could not found anything regarding this within the official docs. So i am assuming there are good reasons why it is not supported. Speaking of that, may i be on the wrong track modelling entities with inheritance in general?
Thomas Lang
  • 1,285
  • 17
  • 35

1 Answers1

2

Currently Spring Data JDBC does not support inheritance.

The reason for this is that inheritance make things rather complicated and it was not at all clear what the correct approach is.

I have a couple of vague ideas how one might create something usable. Different repositories per type is one option, using a single type for persisting, but having some post processing to obtain the correct type upon reading is another one.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
  • I have a use case where inheritance is implemented via JPA and hibernate. It´s a legacy case, which i had to adopt from a former collegue. It uses discriminator values. And i am not happy with that, because all kind of (necessarly not related) data is in one table. Maybe a table per type/class would be better. Anyway. I share your opinion " ...that inheritance make things rather complicated". Therefore i will go on coding that project without inheritance (at least on my entities). – Thomas Lang Mar 10 '20 at 06:28
  • I am looking for similar functionality but the inheritance is only in a nested object - the aggregate root is only one type but has entity with polymorhism. Is there any solution for doing it? Seems custom converter does not work or at least I couldn't come up with working solution. – kirpt Feb 02 '21 at 19:42
  • Could you make that a proper question? – Jens Schauder Feb 03 '21 at 07:06