2019 Nov 13 11:05 AM - edited 2024 Feb 03 5:39 PM
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>
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
33 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.