[ https://issues.apache.org/jira/browse/CAY-2738?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Andrus Adamchik updated CAY-2738: --------------------------------- Description: A pair of DbRelationships between two tables is really a single set of joins, not two independent relationships. We should represent it in Cayenne as such. E.g. [*]: {noformat} public class DbRelationshipSide { DbEntity entity; String name; // complementary "other" side DbRelationshipSide otherSide; // list of columns that matches the order on the complementary "other" side List<String> joinColumns; boolean toMany; } public class DbRelationship { Map<String, DbRelationshipSide> sides; public DbRelationshipSide getSide(String dbEntityName) { DbRelationshipSide side = sides.get(dbEntityName); return Objects.requireNonNull(side, () -> "Entity " + dbEntityName + " is not a part of the relationship"); } } {noformat} A single DbRelationship will be linked to both DbEntities, and we won't need to manage two identical sets of joins. From the perspective of an entity, the relationship becomes directed, by accessing its side that matches the entity name. _It remains to be seen if the new API gives us more efficient and easy-to-use data structure. More experimentation is needed._ [*] I am omitting "toDepPk" property in the example. Will discuss improving that separately. was: A pair of DbRelationships between two tables is really a single set of joins, not two independent relationships. We should represent it in Cayenne as such. E.g. [*]: {noformat} public class DbRelationshipSide { DbEntity entity; String name; // complementary "other" side DbRelationshipSide otherSide; // list of columns that matches the order on the complementary "other" side List<String> joinColumns; boolean toMany; } public class DbRelationship { Map<String, DbRelationshipSide> sides; public DbRelationshipSide getSide(String dbEntityName) { DbRelationshipSide side = sides.get(dbEntityName); return Objects.requireNonNull(side, () -> "Entity " + dbEntityName + " is not a part of the relationship"); } } {noformat} A single DbRelationship will be linked to both DbEntities, and we won't need to manage two identical sets of joins. From the perspective of an entity, the relationship becomes directed, by accessing its side that matches the entity name. _It remains to be seen if the new API gives us more efficient and easy-to-use data structure. More experimentation is needed._ [*] I am omitting "toDepPk" property in the example. Will discuss improving that separately. > Mapping Proposal: Directonless DbRelationship > --------------------------------------------- > > Key: CAY-2738 > URL: https://issues.apache.org/jira/browse/CAY-2738 > Project: Cayenne > Issue Type: Improvement > Reporter: Andrus Adamchik > Priority: Major > > A pair of DbRelationships between two tables is really a single set of joins, > not two independent relationships. We should represent it in Cayenne as such. > E.g. [*]: > {noformat} > public class DbRelationshipSide { > DbEntity entity; > String name; > // complementary "other" side > DbRelationshipSide otherSide; > // list of columns that matches the order on the complementary "other" > side > List<String> joinColumns; > boolean toMany; > } > public class DbRelationship { > Map<String, DbRelationshipSide> sides; > public DbRelationshipSide getSide(String dbEntityName) { > DbRelationshipSide side = sides.get(dbEntityName); > return Objects.requireNonNull(side, > () -> "Entity " + dbEntityName + " is not a part of the > relationship"); > } > } > {noformat} > A single DbRelationship will be linked to both DbEntities, and we won't need > to manage two identical sets of joins. From the perspective of an entity, the > relationship becomes directed, by accessing its side that matches the entity > name. > _It remains to be seen if the new API gives us more efficient and easy-to-use > data structure. More experimentation is needed._ > [*] I am omitting "toDepPk" property in the example. Will discuss improving > that separately. -- This message was sent by Atlassian Jira (v8.20.10#820010)