我意識到已經有很多問題詢問有關此異常消息的問題,但我已經閱讀了它們,所提供的修補程序沒有幫助,並且失敗解決我的情況:在使用類層次結構和歧視時遇到這個異常信息。我使用休眠5個註釋和獲得對初始化以下異常(請原諒我的類/變量名稱混淆和我在龍目島的註釋評論,櫃面你不熟悉的龍目島):如何正確映射我的類(通過映射引用未知目標實體屬性)
org.hibernate作爲.AnnotationException:引用的mappedBy未知 目標實體屬性: com.example.entity.Ca在 com.example.entity.A.cs
下面是我的類(與不相關的字段中刪除)
@Entity
@Data // generates getters/setters for all fields
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class A implements Persistable<String> {
@Id
@NonNull
private String id;
@NonNull
@OneToMany(mappedBy = "a", orphanRemoval = true, cascade = PERSIST)
private Set<C> cs;
}
。
@Data //generates getters/setters for all fields as well as toString, equals, and hashCode implementations
@Entity
@NoArgsConstructor //generates a no args constructor (required by hibernate)
@AllArgsConstructor //generates a constructor with all fields present
@DiscriminatorColumn(discriminatorType = INTEGER, name = B.DISCRIMINATOR_NAME)
public abstract class B implements Persistable<UUID> {
protected static final String DISCRIMINATOR_NAME = "direction";
protected static final String DISCRIMINATOR_1_VALUE = "1";
protected static final String DISCRIMINATOR_1_VALUE = "2";
@Id
@GeneratedValue
@Column(columnDefinition = "uuid")
private UUID id;
@NonNull
@ManyToOne(optional = false)
@JoinColumn(nullable = false, updatable = false)
private A a;
}
。
@Entity
@NoArgsConstructor //generates a no args constructor (required by hibernate)
@ToString(callSuper = true) //generates toString method which calls super.toString
@EqualsAndHashCode(callSuper = true) //generates equals and hashCode methods which call their respective methods in the super class
@DiscriminatorValue(B.SEND_DISCRIMINATOR_VALUE)
public class C extends B {
}
那麼,我做錯了什麼?盡我所知,一切都設置正確。
如何使''屬性'受保護'而不是'私人'? – Ish
@Ish沒有效果:( –