0

I'm using Hibernate with "Table per subclass" method. But unfortunately with slightly different table definition than the "best practices" which are described for the subclass-method. This is because the database administrator won't accept the hibernate design with the foreign keys in the subclass-tables but instead he want's foreign keys from the baseclass-table to the subclass-tables

The schema looks like this:

TABLE BASE
ID <PK>
Class-A <FK TABLE A>
Class-B <FK TABLE B>

TABLE A
ID <PK>

TABLE B
ID <PK>

I dont have the opportunity to change the schema without huge discussions about it.

Now to the problem:

If we let hibernate save a derived class, the order of insertion is

hibernate: insert BASE (...)
hibernate: insert A (...)

but with this order, the constraint PK<>FK is violated! What i want hibernate to do is to first insert the subclass A and THEN the "data bag" base class. Does anybody know if and where this can be configured?

fklappan
  • 3,259
  • 2
  • 17
  • 18
  • How are the IDs generated? Is it the same ID in the base table and in the joined tables? The schema looks a lot like a one-to-one relation, if the DBA is not willing to change it, you should remodel your entities to reflect this schema – Guillaume Jul 09 '13 at 13:29
  • The IDs are generated by myself. A one-to-one relation "remodelling" is not possible because the entities are hierarchical... A can contain B which can contain severeal B's and so on... :( – fklappan Jul 09 '13 at 13:49
  • Could you give more details on your entity model? I'd like to see the inheritance tree and the associations – Guillaume Jul 09 '13 at 15:26

0 Answers0