フィールドとデータベース列名の間のリンクを定義するために注釈を使用する 2 つのクラスがあります。これらのクラスは、定義する列名を除いて非常に似ています。
class TableA {
@ForeignName("IDTableA") // Column name in TableC referring to this TableA record
List<TableC> elements;
// Some other field definitions, common between TableA and TableB
// Some other field definitions, specific to TableA
}
class TableB {
@ForeignName("IDTableB") // Column name in TableC referring to this TableB record
List<TableC> elements;
// Some other field definitions, common between TableA and TableB
// Some other field definitions, specific to TableB
}
class TableC {
@LocalName("IDTableA")
TableA refA;
@LocalName("IDTableB")
TableB refB;
}
"IDTableA/B"
定数を与えることができるスーパークラスが欲しいです。理想的には「次のようなもの」です (Generics に型以外のものを指定できないことはわかっていますが、私の主張を説明するためだけに):
abstract class TableAB<IDName> {
@ForeignName(IDName)
List<TableC> elements;
// Field definitions common between TableA and TableB
}
class TableA extends TableAB<"IDTableA"> {
// Field definitions, specific to TableA
}
class TableB extends TableAB<"IDTableB"> {
// Field definitions, specific to TableB
}
それはどういうわけか可能ですか?