3

私はモルフィア github バージョン 1.2.2 を使用しています。モルフィア エンティティの 1 つのフィールドにインデックスに注釈を付ける方法は知っていますが、2 つのフィールドの構成にインデックスに注釈を付ける方法はありますか。たとえば、フィールド a と b に複合インデックスが必要な場合、次のクラスの注釈はどうなるでしょうか。

@Entity
public class TestClass
{
    @Property("a")
    private int fieldA;
    @Property("b")
    private int fieldB;
    //how to annotate index of compound key fieldA and fieldB using morphia index annotation?
}

前もって感謝します。

4

1 に答える 1

8
@Entity
@Indexes(@Index(name = "aAndB", value = "a, b"))
public class TestClass
{
    @Property("a")
    private int fieldA;
    @Property("b")
    private int fieldB;
    //how to annotate index of compound key fieldA and fieldB using morphia index annotation?
}

インデックスに名前を付けるのはオプションです。複合インデックスを一意にすることもできます。

于 2013-01-10T22:46:54.867 に答える