聚合后如何使用 Hibernate OGM 从 MongoDB 中读取 @Embeddable 对象列表。
我有这样的实体
@javax.persistence.Entity
public class MySession implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Type(type = "objectid")
private String id;
private Date start;
private Date end;
@ElementCollection
private List<MySessionEvent> events;
}
和@Embeddable 对象
@javax.persistence.Embeddable
public class MySessionEvent implements Serializable {
private Long time;
private String name;
}
我坚持从本机查询映射可嵌入对象
String queryString = "db.MySession.aggregate([" +
" { '$match': { 'events.name': { '$regex': 'Abrakadabra'} }}, " +
" { '$unwind': '$events' }, " +
" { '$replaceRoot': { 'newRoot': '$events'}} " +
"])";
List<MySessionEvent> objects = em.createNativeQuery(queryString, MySessionEvent.class).getResultList();
我收到一个错误Caused by: org.hibernate.MappingException: Unknown entity