This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository topia. See http://git.nuiton.org/topia.git commit ed14abc6b2b330fc71098c252f9bf5fe224633df Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Apr 16 11:13:58 2015 +0200 refs #3674 Fix reverse attribute name --- .../generator/EntityHibernateMappingGenerator.java | 8 +++- .../nuiton/topia/generator/TopiaGeneratorUtil.java | 49 +++++++++++++++++++++- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java b/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java index 006f385..640d698 100644 --- a/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java +++ b/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java @@ -239,12 +239,16 @@ public class EntityHibernateMappingGenerator extends ObjectModelGenerator { // many to many tableName = TopiaGeneratorUtil.getManyToManyTableName(attribute); - propertyName = TopiaGeneratorUtil.getDbName(attribute.getReverseAttribute()); + //propertyName = TopiaGeneratorUtil.getDbName(attribute.getReverseAttribute()); + // FIX https://forge.nuiton.org/issues/3674 + propertyName = TopiaGeneratorUtil.getReverseDbNameOnReverseAttribute(attribute); } else { // one to many tableName =TopiaGeneratorUtil.getDbName(attribute.getClassifier()); - propertyName = TopiaGeneratorUtil.getDbName(attribute.getReverseAttribute()); + //propertyName = TopiaGeneratorUtil.getDbName(attribute.getReverseAttribute()); + // FIX https://forge.nuiton.org/issues/3674 + propertyName = TopiaGeneratorUtil.getReverseDbNameOnReverseAttribute(attribute); } // add schema if exist (http://nuiton.org/issues/2052) diff --git a/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java b/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java index 4a75ea2..8eabb93 100644 --- a/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java +++ b/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java @@ -24,8 +24,6 @@ package org.nuiton.topia.generator; -import java.util.LinkedHashSet; - import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; @@ -56,6 +54,7 @@ import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -203,6 +202,52 @@ public class TopiaGeneratorUtil extends JavaGeneratorUtil { } /** + * Obtain the reverse db name of a reverse attribute. + * + * <strong>Note that the reverse attribute can't be null here.</strong> + * <ul> + * <li>Try first to get the reverse db Name from the ReverseDbname tag-value</li> + * <li>If not found, try then the ReverseDbname tag-value on the same attribute but from this other side of the relation</li> + * <li>If not found, try then just get the name of the reverse attribute</li> + * </ul> + * @param attr the attribute to seek + * @return the value of the reverse db name on the revser attribute + * @since 2.9.5.2 + */ + public static String getReverseDbNameOnReverseAttribute(ObjectModelAttribute attr) { + + ObjectModelAttribute reverseAttribute = attr.getReverseAttribute(); + + if (reverseAttribute == null) { + throw new IllegalArgumentException("The reverse attribute can't be null, but was on " + attr); + } + + String result = getReverseDbNameTagValue(reverseAttribute); + if (StringUtils.isEmpty(result)) { + + // Try to get it from the other site of the relation + ObjectModelAttribute reverseAttribute2 = reverseAttribute.getClassifier().getAttribute(attr.getName()); + result = getReverseDbNameTagValue(reverseAttribute2); + + } + +// if (StringUtils.isEmpty(result)) { +// +// result = getDbNameTagValue(reverseAttribute); +// +// } + + if (StringUtils.isEmpty(result)) { + + result = toLowerCaseFirstLetter(reverseAttribute.getName()); + + } + + return result; + + } + + /** * Renvoie le nom BD de l'élement passé en paramètre. Elle se base sur le * tag associé si il existe, sinon sur le nom de l'élément * -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.