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.  [ 4 posts ] 
Author Message
 Post subject: Another HQL query to write...
PostPosted: Wed Aug 13, 2008 10:00 am 
Newbie

Joined: Mon Aug 11, 2008 3:17 pm
Posts: 6
Hi.. i have got another "please write me a query" question. This time I have a collection of Teams in each Tournament.. How can I get all tournaments wich contains team with specified Id ?? I want to make it in only one HQL query without adding any special props in my entities section.

Here is my mapping:

Code:
  <class name="Team" table="Teams">

    <id name="Id" column="Id" type="String">
      <generator class="uuid.hex" />
    </id>


    <property name="Name" type="String" length="150">
      <column name="Name" />
    </property>

    <many-to-one name="LeaderId" class="User" cascade="all"  lazy="false" column="LeaderId"/>

    <bag name="Players" cascade="all" lazy="false">
      <key column="TeamId" />
      <one-to-many class="Player" />
    </bag>

  </class>

 
  <class name="Tournament" table="Tournaments">

    <id name="Id" column="Id" type="String">
      <generator class="uuid.hex" />
    </id>

    <many-to-one name="OwnerId" class="User" cascade="all"  lazy="false" column="OwnerId"/>
   
    <property name="Name" type="String" length="150">
      <column name="Name" />
    </property>

    <property name="Mode" type="Int32">
      <column name="Mode" />
    </property>

    <property name="Stages" type="Int32">
      <column name="Stages" />
    </property>

    <bag name="Teams" table="Teams_Tournaments" cascade="all" lazy="false">
      <key column="TournamentId" />
      <many-to-many class="Team" />
    </bag>

    <many-to-one name="Games" class="Game" cascade="all"  lazy="false" column="Games"/>

  </class>


Thanks a lot for all replies wich will come ;)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 13, 2008 11:10 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Example from the doc:

Code:
select mother from Eg.Cat as mother, Eg.Cat as kit
where kit in elements(mother.Kittens)


replace Cat with Tournament, Kittens with Teams.

http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/queryhql.html#queryhql-expressions

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 13, 2008 11:22 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Sorry, has to be more like

select mother from Eg.Cat as mother
where :team in elements(mother.Kittens)

query.SetParameter("team", team);

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 13, 2008 11:47 am 
Newbie

Joined: Mon Aug 11, 2008 3:17 pm
Posts: 6
Thanks again.. I have no idea that object could be a parameter :)

Btw. there are so many HQL queries in the manual, but so little description tu them...


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