ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alan Chandler" <a...@chandlerfamily.org.uk>
Subject Re: Keyed sub selects
Date Mon, 17 Oct 2005 10:33:03 GMT
Gareth Moorst writes: 

Isn't this the classic use of groupBy? 

See the thread earlier entitled "Group By for multiple column primary keys" 

Particularly my last contribution - where I lay out how I was doing this in 
a some detail (I am using Lists rather than hashmaps but whatever). 

> -----Original Message-----
> From: Gareth Moorst 
> Sent: 11 October 2005 15:35
> To: 'user-java@ibatis.apache.org'
> Subject: FW: Keyed sub selects 
> Hi,
> Sorry if this show up three times - I posted it twice last week, and haven't yet seen
it show, so here it is again. 
> I want to be able to do a subselect where the child objects have a specific position
in the parent.
> My database has three tables -  
> Team (the parent)
> Player (the child)
> TeamPlayer (the relationship between them) 
> The Team and Player tables each have a primary key, and the TeamPlayer table has reference
to a team, a player, and the squad number of that player in the team.
> Each player can be in one team or no team. 
> Can I implement this kind of relationship in Ibatis without having to implement a separate
class for the TeamPlayer table?
> I'd like to be able to use ibatis to insert the player objects at the right position
in the team object (using squad number as key in a hashmap, say) but I'm at a loss as to how
to build my sqlmap. 
> Currently I have Java objects: 
> public interface Team
> {
> 	public void setName(String name); //PK
> 	public void getName();
> 	public void getPlayer(int squadNo);
> 	public void setPlayer(int squadNo, Player player)
> 	public HashMap getPlayers();
> 	public void setPlayers(HashMap players);
> } 
> public interface Player
> {
> 	public void setName(String name); //PK
> 	public void getName();
> } 
> My Player sqlmap is simple as, just doing a select * from players,
> but my Team sqlmap is the one I'm having trouble with.
> I wanted to be able to do something like  
> 	<resultMap id="teamResult" class="valueobject.newmodel.impl.TeamImpl">
> 		<result property="homeGround" column="home_ground"/>
> 		<result property="name" column="name"/>
> 		<result property="players" select="selectTeamPlayers" column="name">
> 	</resultMap> 
> where the selectTeamPlayers select creates a HashMap of Players keyed by squad number.

> Is this possible using iBatis?
> Any ideas how I could make it work? 
> =======================================================
> Confidentiality Notice
> This e-mail is confidential and intended for the use of the named recipient only.  If
you are not the intended recipient please notify us by telephone immediately on +44(0)1782
600600 or return it to us by e-mail.  Please then delete it from your system and note that
any use, dissemination, forwarding, printing or copying is strictly prohibited. Any views
or opinions are solely those of the author and do not necessarily represent those of The Caudwell
Holdings group of companies. 
> Encryptions and Viruses
> Please note that this e-mail and any attachments have not been encrypted.  They may therefore
be liable to be compromised.  Please also note that it is your responsibility to scan this
e-mail and any attachments for viruses.  We do not, to the extent permitted by law, accept
any liability (whether in contract, negligence or otherwise) for any virus infection and/or
external compromise of security and/or confidentiality in relation to transmissions sent by
> Monitoring 
> Activity and use of The Caudwell Holdings group of companies' systems is monitored to
secure its effective use and operation and for other lawful business purposes.  Communications
using these systems will also be monitored and may be recorded to secure effective use and
operation and for other lawful business purposes. 

Alan Chandler

View raw message