English 中文(简体)
Hibernateynex for using both fetch/select
原标题:Hibernate Syntax for using both fetch/select

I am having some trouble mixing and matching fetches and selects using hibernate. Basically, I am listing a bunch of users in a user table which also contains a "createdBy" column which references the user table by id Ex:

id  | name | foo | createdBy
----------------------------
1     abc    zzz   2
2     def    zzz   2

因此, 在上述例子中,我要举一个例子,说明为“abc”制造的“def”用户将被退回。 页: 1

因此,如果没有创建的By,我就认为:

from User u inner join fetch e.foo as foo inner join fetch foo.bar as bar

我如何插入

"select User u2 from User where u2.id=u.createdBy" 

进入先前的询问?

最佳回答

假定<代码>createdBy 载于。 用户实体为ManyTo One

from User u
  join fetch u.foo as foo
  join fetch foo.bar as bar
  join fetch u.createdBy

如果它没有被描绘成<代码>Many ToOne(而不是?)并且只绘制了它的身份证,那么你就不得不使用一个十字架AND<>em>。 因此:

select u, u2
  from User u, User u2
    join fetch u.foo as foo
    join fetch foo.bar as bar
 where u.createdBy = u2.id

不用说,第一种选择(打字<代码>createdBy作为ManyToOne)更为简单。

问题回答

暂无回答




相关问题
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)