ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gareth Moorst" <Gareth.Moo...@Phones4u.co.uk>
Subject Keyed sub selects
Date Fri, 07 Oct 2005 10:31:18 GMT
Before acting on this e-mail or opening any attachments you are advised to read 
The Caudwell Holdings group of companies' disclaimer at the end of this e-mail.
=======================================================

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.

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
e-mail.

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.


Mime
View raw message