I have DisseminationArea as subcalss for Feature with the following code:
@Entity
@Table(name = "features")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "subtype_id", discriminatorType = DiscriminatorType.INTEGER)
public class Feature {
@Id
@Column(name="id")
@GeneratedValue(generator="sqlite")
@TableGenerator(name="sqlite", table="sqlite_sequence",
pkColumnName="name", valueColumnName="seq",
pkColumnValue="features")
@Getter
@Setter
private long id;
@ManyToOne
@JoinColumn(name = "subtype_id")
@Getter
@Setter
private FeatureSubtype featureSubtype;
@ManyToOne
@JoinColumn(name = "parent_id")
@Getter
@Setter
private Feature parent;
...
}
Unfortunately, this causes an exception when save this entity to database, because subtype_id field is used twice.
Can I annotate it somehow so that JPA know it is the same field?
Same column name is used for relation FK to FeatureSubtype. Use other name for discriminator or don't use discriminator at all.
In Hibernate, discriminator column on joined inheritance is supported but not required. Hibernate is querying all subtables to determine correct subclass.