-->
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.  [ 11 posts ] 
Author Message
 Post subject: inner join
PostPosted: Tue Nov 04, 2003 11:02 am 
Newbie

Joined: Tue Nov 04, 2003 10:54 am
Posts: 6
hello,

I was wondering if there was a way to generate inner join instead of outer join for getting sub objects.

I have a class User and a class Group. One user is necessairly in a group and a group can have more than one user.

My pleasure would be to generate almost this :
select * from user, group where user.grp = group.grp

my mapping is the following :

Code:
<hibernate-mapping>
   <class name="com.unimondes.model.User" table="T_USER">
      <id name="idUser"  unsaved-value="null">
         <column name="USR_ID" sql-type="long" not-null="true" />
         <generator class="native">
                <param name="sequence">seq_usr_id</param>
            </generator>
      </id>

      <property name="login" column="USR_LOGIN" />
      <property name="password" column="USR_PASSWORD" />
        <many-to-one name="group" class="com.unimondes.model.Group" column="GRP_ID" not-null="true" />
   </class>
    <class name="com.unimondes.model.Group" table="T_GROUP">
        <id name="idGroup"  unsaved-value="null">
            <column name="GRP_ID" sql-type="long" not-null="true" />
            <generator class="native">
                <param name="sequence">seq_grp_id</param>
            </generator>
        </id>

        <property name="name" column="GRP_NAME" />
       
    </class>
</hibernate-mapping>


May I do better ???

Thx in advance


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2003 11:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Sure. just use a query with an inner join.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2003 11:16 am 
Newbie

Joined: Tue Nov 04, 2003 10:54 am
Posts: 6
here is my query :

select user from User as user where user.login = :login and user.password = :password

How can I modify the query to tell hibernate to look for user.group in my group table ?

I'm not used to this dialect yet...sorry !


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2003 11:19 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
select user from User as user inner join user.group as group where user.login = :login and user.password = :password and group.id = :groupId


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2003 11:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Or just:


from User as user where user.login = :login and user.password = :password and user.group.id = :groupId


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2003 11:32 am 
Newbie

Joined: Tue Nov 04, 2003 10:54 am
Posts: 6
doesn't work, i don't understand the error log !

here is what is generated :

select user from com.unimondes.model.User as user inner join user.group as group where user.login = :login and user.password= :password and group.idGroup = :id

is group.id necessary because i just want an inner join ?

where am i wrong ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2003 11:33 am 
Newbie

Joined: Tue Nov 04, 2003 10:54 am
Posts: 6
the error is :

javax.servlet.ServletException: BY expected after GROUP or ORDER


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2003 12:11 pm 
Newbie

Joined: Tue Nov 04, 2003 10:54 am
Posts: 6
maybe i'm wrong, but if i understand well :
it makes sense that "select user from User as user" gets back user.group (from the group table).

I just want to eliminate the outer join, which is not optimum !!

any idea ??


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2003 12:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
from User user inner join fetch user.group


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2003 12:40 pm 
Newbie

Joined: Tue Nov 04, 2003 10:54 am
Posts: 6
argh !!!

iterate() and scroll() doesn't work with fetch !

am i asking something weird ??? or what ???

I didn't find anything on it in the forum ? is it ok for everyone to use outer join to link tables with 1-n relation ???

or probably nobody looked at it....

Sorry for my beginner talent !


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2003 1:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
iterate and scroll don't make sense with fetch


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 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.