Sun Java System Application Server Enterprise Edition 8.1 2005Q2 Developer's Guide

- Previous: The sun-ejb-jar.xml File
- Next: The sun-application-client.xml file

# The sun-cmp-mappings.xml File

The element hierarchy in the `sun-cmp-mappings.xml` file is as follows:

    sun-cmp-mappings
    .  sun-cmp-mapping
    .  .  schema
    .  .  entity-mapping
    .  .  .  ejb-name
    .  .  .  table-name
    .  .  .  cmp-field-mapping
    .  .  .  .  field-name
    .  .  .  .  column-name
    .  .  .  .  read-only
    .  .  .  .  fetched-with
    .  .  .  .  .  default
    .  .  .  .  .  level
    .  .  .  .  .  named-group
    .  .  .  .  .  none
    .  .  .  cmr-field-mapping
    .  .  .  .  cmr-field-name
    .  .  .  .  column-pair
    .  .  .  .  .  column-name
    .  .  .  .  fetched-with
    .  .  .  .  .  default
    .  .  .  .  .  level
    .  .  .  .  .  named-group
    .  .  .  .  .  none
    .  .  .  secondary-table
    .  .  .  .  table-name
    .  .  .  .  column-pair
    .  .  .  .  .  column-name
    .  .  .  consistency
    .  .  .  .  none
    .  .  .  .  check-modified-at-commit
    .  .  .  .  lock-when-loaded
    .  .  .  .  check-all-at-commit
    .  .  .  .  lock-when-modified
    .  .  .  .  check-version-of-accessed-instances
    .  .  .  .  .  column-name

Here is a sample database schema definition:

    create table TEAMEJB (
    TEAMID varchar2(256) not null,
     NAME varchar2(120) null,
     CITY char(30) not null,
     LEAGUEEJB_LEAGUEID varchar2(256) null,
     constraint PK_TEAMEJB primary key (TEAMID)
    )
    create table PLAYEREJB (
    POSITION varchar2(15) null,
     PLAYERID varchar2(256) not null,
     NAME char(64) null,
     SALARY number(10, 2) not null,
     constraint PK_PLAYEREJB primary key (PLAYERID)
    )
    create table LEAGUEEJB (
    LEAGUEID varchar2(256) not null,
     NAME varchar2(256) null,
     SPORT varchar2(256) null,
     constraint PK_LEAGUEEJB primary key (LEAGUEID)
    )
    create table PLAYEREJBTEAMEJB (
    PLAYEREJB_PLAYERID varchar2(256) null,
     TEAMEJB_TEAMID varchar2(256) null
    )
    alter table TEAMEJB
    add constraint FK_LEAGUE foreign key (LEAGUEEJB_LEAGUEID)
    references LEAGUEEJB (LEAGUEID)
    alter table PLAYEREJBTEAMEJB
    add constraint FK_TEAMS foreign key (PLAYEREJB_PLAYERID)
    references PLAYEREJB (PLAYERID)
    alter table PLAYEREJBTEAMEJB
    add constraint FK_PLAYERS foreign key (TEAMEJB_TEAMID)
    references TEAMEJB (TEAMID)

Here is a corresponding sample `sun-cmp-mappings.xml` file:

    <?xml version="1.0" encoding="UTF-8"?>
    <sun-cmp-mappings>
    <sun-cmp-mapping>
    	<schema>Roster</schema>
    	<entity-mapping>
    		<ejb-name>TeamEJB</ejb-name>
    		<table-name>TEAMEJB</table-name>
    		<cmp-field-mapping>
    			<field-name>teamId</field-name>
    			<column-name>TEAMEJB.TEAMID</column-name>
    		</cmp-field-mapping>
    		<cmp-field-mapping>
    			<field-name>name</field-name>
    			<column-name>TEAMEJB.NAME</column-name>
    		</cmp-field-mapping>
    		<cmp-field-mapping>
    			<field-name>city</field-name>
    			<column-name>TEAMEJB.CITY</column-name>
    		</cmp-field-mapping>
    		<cmr-field-mapping>
    			<cmr-field-name>league</cmr-field-name>
    			<column-pair>
    				<column-name>TEAMEJB.LEAGUEEJB_LEAGUEID</column-name>
    				<column-name>LEAGUEEJB.LEAGUEID</column-name>
    			</column-pair>
    			<fetched-with>
    				<none/>
    			</fetched-with>
    		</cmr-field-mapping>
    		<cmr-field-mapping>
    			<cmr-field-name>players</cmr-field-name>
    			<column-pair>
    				<column-name>TEAMEJB.TEAMID</column-name>
    				<column-name>PLAYEREJBTEAMEJB.TEAMEJB_TEAMID</column-name>
    			</column-pair>
    			<column-pair>
    				<column-name>PLAYEREJBTEAMEJB.PLAYEREJB_PLAYERID</column-name>
    				<column-name>PLAYEREJB.PLAYERID</column-name>
    			</column-pair>
    			<fetched-with>
    				<none/>
    			</fetched-with>
    		</cmr-field-mapping>
    	</entity-mapping>
    	<entity-mapping>
    		<ejb-name>PlayerEJB</ejb-name>
    		<table-name>PLAYEREJB</table-name>
    		<cmp-field-mapping>
    			<field-name>position</field-name>
    			<column-name>PLAYEREJB.POSITION</column-name>
    		</cmp-field-mapping>
    		<cmp-field-mapping>
    			<field-name>playerId</field-name>
    			<column-name>PLAYEREJB.PLAYERID</column-name>
    		</cmp-field-mapping>
    		<cmp-field-mapping>
    			<field-name>name</field-name>
    			<column-name>PLAYEREJB.NAME</column-name>
    		</cmp-field-mapping>
    		<cmp-field-mapping>
    			<field-name>salary</field-name>
    			<column-name>PLAYEREJB.SALARY</column-name>
    		</cmp-field-mapping>
    		<cmr-field-mapping>
    			<cmr-field-name>teams</cmr-field-name>
    			<column-pair>
    				<column-name>PLAYEREJB.PLAYERID</column-name>
    				<column-name>PLAYEREJBTEAMEJB.PLAYEREJB_PLAYERID</column-name>
    			</column-pair>
    			<column-pair>
    				<column-name>PLAYEREJBTEAMEJB.TEAMEJB_TEAMID</column-name>
    				<column-name>TEAMEJB.TEAMID</column-name>
    			</column-pair>
    			<fetched-with>
    				<none/>
    			</fetched-with>
    		</cmr-field-mapping>
    	</entity-mapping>
    	<entity-mapping>
    		<ejb-name>LeagueEJB</ejb-name>
    		<table-name>LEAGUEEJB</table-name>
    		<cmp-field-mapping>
    			<field-name>leagueId</field-name>
    			<column-name>LEAGUEEJB.LEAGUEID</column-name>
    		</cmp-field-mapping>
    		<cmp-field-mapping>
    			<field-name>name</field-name>
    			<column-name>LEAGUEEJB.NAME</column-name>
    		</cmp-field-mapping>
    		<cmp-field-mapping>
    			<field-name>sport</field-name>
    			<column-name>LEAGUEEJB.SPORT</column-name>
    		</cmp-field-mapping>
    		<cmr-field-mapping>
    			<cmr-field-name>teams</cmr-field-name>
    			<column-pair>
    				<column-name>LEAGUEEJB.LEAGUEID</column-name>
    				<column-name>TEAMEJB.LEAGUEEJB_LEAGUEID</column-name>
    			</column-pair>
    			<fetched-with>
    				<none/>
    			</fetched-with>
    		</cmr-field-mapping>
    	</entity-mapping>
    </sun-cmp-mapping>
    </sun-cmp-mappings>

- Previous: The sun-ejb-jar.xml File
- Next: The sun-application-client.xml file

- © 2010, Oracle Corporation and/or its affiliates