作者:晨风流云 | 来源:互联网 | 2023-06-15 16:35
IhaveDisseminationAreaassubcalssforFeaturewiththefollowingcode:我使用以下代码将DisseminationArea作
I have DisseminationArea
as subcalss for Feature
with the following code:
我使用以下代码将DisseminationArea作为Feature的subcalss:
@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.
不幸的是,这会在将此实体保存到数据库时导致异常,因为subtype_id字段使用了两次。
Can I annotate it somehow so that JPA know it is the same field?
我可以以某种方式对其进行注释,以便JPA知道它是同一个字段吗?
2 个解决方案