English 中文(简体)
JPA/Hibernate selected elements not in Collection
原标题:JPA/Hibernate select element not in collection

如果我有两个实体类别,即:GroupPerson,如果在groupPerson之间有一对一的关系(即,一个人可以属于多数集团,一个群体可以有许多人),那么,那么,我可以选择所有<密码>。 姓名/代码

Something like the reverse of select p from Group g inner join g.people p...

最佳回答

这项工作:

select p from Person p where p not in (select pg from Group g inner join g.persons pg)

或许:

select p from Person p where not exists (select 1 from Group g where p member of g.persons)

效率更高?

不管怎样,......欢迎对哪些方面更有效率的意见,但因为这两个“工作”都把问题列为回答。

问题回答

If you want to have all persons who are not in a given group g, it should be like

from Person p where p.group.id != :gid;

并且,你给特定群体的补贴。

如果你想要所有没有团体的人,

from Person p where p.group.id is null;

如果你想让所有没有群体的人都到别处,但外国关键人物有可能拥有一个不属于任何集团但不属于现有集团的群体的群体的群体的群体(例如,如果该群体被删除而没有将这些人删除,也没有将他们转移到另一个群体)

from Person p where not exist (select 1 from Group g where g.id = p.group.id);

P. S. 我的发言是代表总部,但对于联合人民党来说,发言应大致相同。





相关问题
Multiple Hibernate instances using C3P0

I am facing a weird problem and it seems to be c3p0 related. I am starting two instances of an app in the same java vm which interact with each other. After some operations "APPARENT DEADLOCK" ...

Hibernate vs Ibatis caching

We can speed up a hibernate app easyly with 2nd level cache using infinispan or ehcache/terracotta,... but ibatis only have a simple interface to implement for caching. And hibernate knows more ...

Using annotations to implement a static join in hibernate

I m relatively new to hibernate and was wondering if someone could help me out. While I have no issues implementing a normal join on multiple columns in hibernate using the @JoinColumns tag, I m ...

Hibernate query with fetch question

I have a 2 entities in a One-To-Many relationship: OfficeView.java: public class OfficeView implements java.io.Serializable { private Integer officeId; private String addr1; private ...

hibernate interceptors : afterTransactionCompletion

I wrote a Hibernate interceptor : public class MyInterceptor extends EmptyInterceptor { private boolean isCanal=false; public boolean onSave(Object entity, Serializable arg1, Object[] arg2, String[]...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

Hibernate/GORM: collection was not processed by flush()

I have an integration test in my Grails application that fails when I try to save an entity of type Member invitingMember.save(flush: true) This raises the following exception org.hibernate....

Hibernate Criteria API equivalent for "elements()"

Is it possible to implement the following query using Criteria API? select order from ORDER as order,ITEM as item where item.itemID like ITM_01 and item in elements(order.items)

热门标签