-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: SubQuery In Select List
PostPosted: Tue Dec 05, 2017 2:23 am 
Newbie

Joined: Tue Dec 05, 2017 2:10 am
Posts: 1
Hi,
I want to use subquery in POJO Class.

example :

I have User class.

@Column
private String userName;
@Column
private String userCode;


And I have some other class like LoggedUsers

@Column
private String loggedUserCode;

@Column
private String loggedUserName;



In the above LoggedUsers pojo class, I want loggedUserName from User class.

Like;

Select (Select userName From User WHERE userCode = loggedUserCode ) FROM LoggedUsers


Top
 Profile  
 
 Post subject: Re: SubQuery In Select List
PostPosted: Tue Dec 05, 2017 5:49 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1638
Location: Romania
Better use a join instead:

Code:
SELECT
    u.userName
FROM LoggedUsers lu
JOIN User u ON u.userCode = lu.loggedUserCode


You can even map this SQL query to a DTO. Check out this article for more details.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.