2016-05-16 108 views
0

我在这里有下面的表格,但在获取结果时有一些问题。关联的HQL查询

@Entity 
@Table(name = "USER_VW") 
public class WorkspaceUserImpl 
{ 
    @JoinColumn(name = "USER_ID", insertable=false, updatable=false) 
    @OneToOne(targetEntity = UserImpl.class, fetch = FetchType.EAGER) 
    private User user; 

} 

@Table(name = "IK_USER") 
@Inheritance(strategy = InheritanceType.JOINED) 
@AttributeOverride(name = "id", column = @Column(name = "USER_ID")) 


    public class UserImpl extends BaseAuditable<UserIdentifier>implements User, UserAuthentication { 

     private static Logger log = LoggerFactory.getLogger(UserImpl.class); 

     @Id 
     @Type(type = "com.commons.UserIdentifierTypeMapper") 
     @Column(name = "USER_ID") 
     private UserIdentifier id; 
    } 

和用户

Public Inteface User 
{ 
     UserIdentifier getId(); 
} 

现在我已经写一个HQL查询词中包含用于UserImpl类给定的用户ID来从WorkspaceUserImpl类的所有数据。

SELECT w from WorkspaceUserImpl w where w.user.id = : user_id; 

,也试过

SELECT w from WorkspaceUserImpl as w INNER JOIN w.user as u where u.id = : user_id; 

,甚至与试图JOIN也FETCH

和设置参数USER_ID一些说1234

,但我得到的名单emply对于部分ID而言在DB中它有5条记录。

我在这里做任何查询错误?好心的建议..

+0

我相信你会需要一个叫做'User'适当到Hibernate可以加入'WorkspaceUserImpl'类。实现'用户'是不够的。 –

+0

由于它的旧代码,我不允许在hirarchy中做任何修改......我的HQL如何?我做了什么是正确的? –

回答

0

你试过下面的查询:

from WorkspaceUserImpl as w JOIN FETCH w.user as u where u.id = : user_id; 
+0

我还没试过呢....我会让你知道结果..谢谢shankarsh .. –