私のアプリケーションでhibernate ogm 5.1を使用しています。このクエリを構成しています。このクエリ集約クエリのHibernate OGM結果
String query = "db.SWMessages.aggregate([ {0}, {1} ])";
Document q1 = new Document("$match",new Document("messageUuid",new
Document("$ne" , id.toString())));
Document q2 = new Document("$group", new Document("_id",
"$localReference").append("max", new Document("$max","$creationDate")));
Object[] param = { q1.toJson(), q2.toJson() };
String nativeQuery = MessageFormat.format(query, param);
List<SWMessageR> records = (List<SWMessageR>) em.createNativeQuery(nativeQuery, SWMessageImpl.class)
.getResultList();
は、上記のコードは、このようなクエリを生成します。
db.SWMessages.aggregate([ { "$match" : { "messageUuid" : { "$ne" : "9c1464d7-311d-4b50-8b81-005bad055232" } } } , { "$group" : { "_id" : "$localReference", "max" : { "$max" : "$creationDate" } } } ])
私の質問は、このクエリの結果はSWMessageRあるエンティティオブジェクトをバック返すだろうということですか?
お返事ありがとうございます。しかし、上記のクエリは複数のエントリを持ち、あなたの提案する方法は役に立ちません。問題は、グループクエリによって返されたドキュメントが変換されるため、ハイバネートがクエリ結果をエンティティオブジェクトにマップできないという永続性例外が発生する可能性があり、mongoドキュメントを参照することをお勧めします。乾杯 – Invokergb