私は典型的な問題に直面しています。オブジェクト間の典型的な1-Nの関係を想像してください。正確なユーザー(U)とルーム(R):[U] * --- 1 [R]。JPA MappedSuperclass with ManyToOne
ここで問題が発生します。Roomは、BlueRoom、RedRoomなどの実装を含む抽象基本クラスである必要があります。ユーザーエンティティ内での関係の設定方法
public interface Room { ... }
@MappedSuperclass
public abstract class RoomSuperclass implements Room { ... }
@Entity
public class BlueRoom extends RoomSuperclass { ... }
@Entity
public class RedRoom extends RoomSuperclass { ... }
@Entity
public class User {
@ManyToOne(targetEntity = ???) // I don't know if it will be BlueRoom or RedRoom
private Room room; // ManyToOne cannot be applied on mapped superclass
}
私はこれはおそらく代わりに@MappedSuperclassのRoomSuperclassに@Entityを使用することによって解決できる知っているが、私はそれが良い解決策であり、任意のより良い1があるかどうかはわかりません。
はい、解決策です。あなたが何かに関連しているなら、この何かは実体でなければなりません。 –
返信ありがとうJB、私は誰か他の人が返信して質問を閉じると2日待っています – d1x