cancel
Showing results for 
Search instead for 
Did you mean: 

use of ordered attribute in many-to-many relation

anirol-10
Discoverer
0 Kudos
1,979

What is the use of ordered attribute in many to many relation? Is it used for any sequencing or for any specific sorting order?

example code:

<relation code="ProductOperationProductRelation" autocreate="true" generate="true" localized="false"> <deployment table="ProductBadgeRelation" typecode="15020" /> <sourceElement qualifier="badges" type="ProductOperation" cardinality="many" ordered="true"> <description>Badges</description> <modifiers read="true" write="true" search="true" optional="true" /> </sourceElement> <targetElement qualifier="products" type="Product" cardinality="many" collectiontype="list" ordered="true"> <description>Products</description> <modifiers read="true" write="true" search="true" optional="true" /> </targetElement> </relation>

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member620692
Active Contributor
0 Kudos

It doesn't have to do anything with sorting. It's definition is:

If 'true' an additional ordering attribute will be generated for maintaining ordering. Default is 'false'.

To validate this definition, put the following code in the items.xml and execute ant

<items 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
			xsi:noNamespaceSchemaLocation="items.xsd">
	<relations>
        <relation code="Item1toItem2" localized="false" generate="true" autocreate="true">
            <sourceElement type="Item1" qualifier="item1" cardinality="one">
                <modifiers read="true" write="true" search="true" optional="true"/>
            </sourceElement>
            <targetElement type="Item2" qualifier="item2s" cardinality="many" ordered="true">
                <modifiers read="true" write="true" search="true" optional="true"/>
            </targetElement>
        </relation>
    </relations>		


	<itemtypes>
		<itemtype generate="true" code="Item1" jaloclass="org.training.jalo.Item1" autocreate="true">
			<deployment table="Item1" typecode="30000"/>
			<attributes>
				<attribute qualifier="attr1Item1" type="java.lang.String">
					<persistence type="property"/>
				</attribute>
			</attributes>
		</itemtype>
		<itemtype generate="true" code="Item2" jaloclass="org.training.jalo.Item2" autocreate="true">
			<deployment table="Item2" typecode="30001"/>
			<attributes>
				<attribute qualifier="attr1Item2" type="java.lang.String">
					<persistence type="property"/>
				</attribute>
			</attributes>
		</itemtype>
	</itemtypes>
</items>

Then open the generated Java files Item1.java and Item2.java from gensrc folder. You will find that "item1POS" has been added in both, Item1.java and Item2.java and its purpose is to keep track of postion (order) of elements in the collection.

You can also try after removing ordered="true" and then you will find "item1POS" missing from both, Item1.java and Item2.java.

crescenzorega
Active Participant
0 Kudos