Closed feo81 closed 4 years ago
I didn't know, that an intermediate @MappedSuperclass
is even possible, I usually use those classes only as base classes for entities.
But anyway, I think it is more likely that the problem is line 438 where the &&
is applied first, while it should be the ||
:
if (this.inheritanceType == null && this.entityClass.isAnnotationPresent(DiscriminatorColumn.class)
|| this.entityClass.isAnnotationPresent(DiscriminatorValue.class)) {
this.inheritanceType = InheritanceType.SINGLE_TABLE;
}
I guess you are defining a @DiscriminatorValue
and that will reset the already inherited inheritanceType
from JOINED
back to SINGLE_TABLE
.
Can you check what happens if you drop the @DiscriminatorValue
?
May be you right, and the problem is in other line. I didn't test it hard. But I don't have @DiscriminatorValue annotation in my structure. Your generator takes this value from entity class name.
I've created a test case with your example and it is working correctly.
I fixed the problem with the @DiscriminatorValue
for 1.5.0 but as you said, this is not your problem.
I fixed another problem, if one has a deeper hierarchy (an entity subclass of an entity subclass of an entity class) and if there are references between those entities. But this doesn't apply to your example, too
In this "if" condition body I don't see the row like "this.inheritanceType = parentDescription.inheritanceType;", so "inheritanceType" value of my target class (1) keeps its default value, equals to "SINGLE_TABLE".
I see that just before in line 618:
if (this.inheritanceType == null) {
this.inheritanceType = parentDescription.inheritanceType;
...
}
And that should be enough, because this.inheritanceType != null
would only happen, if you have added @Inheritance(strategy = InheritanceType.JOINED)
to the subclass (class (1)
). Which would be an error, as that annotation is only allowed for the root class.
Could you add some more example code so I can reproduce your problem?
Sorry, but I can't show you my example. It's a huge project, so the error may be of another cause. I will wait for v.1.5.0 release, so this issue can be closed.
I'm closing the issue in preparation of the 1.5.0 release. If you find, that the issue still exists with 1.5.0, feel free to reopen it again.
Hello again!
Catched the InheritanceType.JOINED bug (v.1.4.1). My class structure consists of 3 classes: @Entity class (1) extends @MappedSuperclass class (2) extends @Entity class (3) with @Inheritance(strategy = InheritanceType.JOINED) So, I'm trying to generate inserts by class (1) objects and catching NPE on null discriminaror column.
The problem, I see, is in EntityClass.findHierarchyRoot method. At line 623 the condition "if (parentDescription.getInheritanceType() == InheritanceType.JOINED)" returns true, so the parent class (3) and its context defines correctly. But. In this "if" condition body I don't see the row like "this.inheritanceType = parentDescription.inheritanceType;", so "inheritanceType" value of my target class (1) keeps its default value, equals to "SINGLE_TABLE".
And then the EntitySqlGenerator.writeInserts method (lines 259-260) has not null "discriminator" value, but null "classDescription.getDiscriminatorColumn()" result