class MyEntity {
... important fields here
@ManyToMany
private List<AnotherEntity> anotherEntities = new ArrayList<AnotherEntity>();
}
所以我想做的是写一个查询
TypedQuery<MyEntity> query = em.createQuery("from MyEntity me where :anotherentity in me.anotherEntities", AnotherEntity.class);
获取所有MyEntity,其中引用了具体的AnotherEntity。我知道这个查询是错误的。它只是向你展示我的意思。
我不想用双向映射来解决这个问题。
最诚挚的问候!
答案 0 :(得分:1)
TypedQuery<MyEntity> query =
em.createQuery("select me from MyEntity me"
+ " where :anotherentity member of me.anotherEntities",
MyEntity.class);