-->
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: question is "select new"
PostPosted: Wed Aug 02, 2006 5:07 pm 
Newbie

Joined: Wed Aug 02, 2006 4:41 pm
Posts: 1
the box class ...
public class Box extends AbstractBox implements java.io.Serializable{
private User TUserInfo;
private Integer boxid;
private String boxname;
public Box(Integer boxid, User TUserInfo, String boxname) {
super(boxid, TUserInfo, boxname);
}
.....get set mehod .....
}

the user class
pubilc class User extends AbstractUser implements java.io.Serializable {
private Integer userid;
private Integer username;
private Set TUserBoxes = new HashSet(0);
.....get set mehod .....
}

user(one) ------ box(many)


is hql ....
select new Box(a.boxid,a.TUserInfo,a.boxname) from Box a
---------------------------------------------------------------------
console sql .....
select
box0_.boxid as col_0_0_,
box0_.userid as col_1_0_,
box0_.boxname as col_2_0_
from test.t_user_box box0_, test.t_user_info user1_
where box0_.userid=user1_.userid
---------------------------------------------------------------------
what is only userid? username?

is hql ...
select a.boxid,a.boxname,a.TUserInfo from Box a
---------------------------------------------------------------------
select
box0_.boxid as col_0_0_,
box0_.boxname as col_1_0_,
box0_.userid as col_2_0_,
user1_.userid as userid, user1_.
username as username2_
from test.t_user_box box0_, test.t_user_info user1_
where box0_.userid=user1_.userid
---------------------------------------------------------------------
now userid and username being

hql
select new Box(intger,new User(intger,string),string) from box
in this way may?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 02, 2006 5:58 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
I couldnt understand clearly from your post, Try the following code if your intent is to get Box and User object using HQL option.

Code:
String hql = "From Box b, User u where b.userid = u.userid";
Query q = session.createQuery( hql );
List results = q.list();
for ( int a = 0; a < results.size(); a++ ) {
   Object[] data = ( Object[] ) results.get( a );
   if ( data[ 0 ] instanceof Box ) {
      Box boxObject = ( Box ) data[ 0 ];
      // you can user object from box iff you have bi-directional
      // relation enabled in mapping file
      User userObject = boxObject.getUser();
   } else if ( data[ 1 ] instanceof Box ) {
      // this also gives you user object
      User userObject = ( User ) data[ 1 ];
   }
}


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.