Author: bleny Date: 2014-02-17 11:36:58 +0100 (Mon, 17 Feb 2014) New Revision: 3011 Url: http://nuiton.org/projects/topia/repository/revisions/3011 Log: fixes #3085 Generated mapping for a property of type enumeration with multiplicity is wrong: fix mapping Modified: trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityHibernateMappingGenerator.java Modified: trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityHibernateMappingGenerator.java =================================================================== --- trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityHibernateMappingGenerator.java 2014-02-14 09:02:16 UTC (rev 3010) +++ trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityHibernateMappingGenerator.java 2014-02-17 10:36:58 UTC (rev 3011) @@ -644,6 +644,8 @@ String collType = TopiaGeneratorUtil.getNMultiplicityHibernateType(attr); String lazy = generateFromTagValue(HIBERNATE_ATTRIBUTE_LAZY, TopiaGeneratorUtil.getLazyTagValue(attr)); String attrColumn = TopiaGeneratorUtil.getDbName(attr); + boolean attrIsEnumeration = attr.getClassifier() != null + && attr.getClassifier().isEnum(); /*{<%=prefix%> <<%=collType%> name="<%=attrName%>" <%=lazy%>node="<%=attrName%>"> <%=prefix%> <key column="OWNER"/> @@ -652,9 +654,30 @@ /*{<%=prefix%> <list-index/> }*/ } + + if (attrIsEnumeration) { + boolean useEnumerationName = TopiaGeneratorUtil.hasUseEnumerationNameTagValue(attr, model); +/*{<%=prefix%> <element column="<%=attrColumn%>" node="id"> +<%=prefix%> <type name="org.hibernate.type.EnumType"> +<%=prefix%> <param name="<%=org.hibernate.type.EnumType.ENUM%>"><%=attrType%></param> +}*/ + // if the user tuned the model to use name instead of + // ordinal to store the values, we must add a clause + if (useEnumerationName) { + String enumSQLType = String.valueOf(Types.VARCHAR); +/*{<%=prefix%> <!-- using name instead of ordinal to store enumeration value --> +<%=prefix%> <param name="<%=org.hibernate.type.EnumType.TYPE%>"><%=enumSQLType%></param> +}*/ + } +/*{<%=prefix%> </type> +<%=prefix%> </element> +}*/ + } else { /*{<%=prefix%> <element type="<%=attrType%>" column="<%=attrColumn%>" node="id"/> -<%=prefix%> </<%=collType%>> }*/ + } +/*{<%=prefix%> </<%=collType%>> +}*/ } protected void generateHibernateManyToOne(Writer output,