Patch to allow reverse engineering to work with tables and associations ending with "s"

Description

Index: java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java
===================================================================
— java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java (revision 9925)
+++ java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java (working copy)
@@ -86,6 +86,10 @@
return StringHelper.unqualify(getMappedClassName());
}

+ public String getShortNamePlural() {
+ return ReverseEngineeringStrategyUtil.simplePluralize(getShortName());
+ }
+
public String getQualifiedDeclarationName() {
String generatedName = getMetaAsString( MetaAttributeConstants.GENERATED_CLASS );
if ( generatedName == null || generatedName.trim().length() == 0 ) {
Index: java/org/hibernate/tool/hbm2x/pojo/POJOClass.java
===================================================================
— java/org/hibernate/tool/hbm2x/pojo/POJOClass.java (revision 9925)
+++ java/org/hibernate/tool/hbm2x/pojo/POJOClass.java (working copy)
@@ -74,7 +74,8 @@

public String getPackageName();
public String getShortName();
-
+ public String getShortNamePlural();
+
public Iterator getToStringPropertiesIterator();
public Iterator getEqualsHashCodePropertiesIterator();

Index: templates/seam/editorbean.java.ftl
===================================================================
— templates/seam/editorbean.java.ftl (revision 9925)
+++ templates/seam/editorbean.java.ftl (working copy)
@@ -1,5 +1,5 @@
${pojo.getPackageDeclaration()}
-// Generated ${date} by Hibernate Tools ${version}
+// Generated ${date} by Hibernate Tools ${version}-jab

<#assign classbody>
<#assign entityEditor = pojo.shortName.toLowerCase() + "Editor"><#assign entityFinder = pojo.shortName.toLowerCase() + "Finder"><#assign entityList = pojo.shortName.toLowerCase() + "List"><#assign entity = pojo.shortName.toLowerCase()><#assign entityClass = pojo.importType(pojo.qualifiedDeclarationName)>
@@ -38,7 +38,7 @@
@${pojo.importType("org.jboss.seam.annotations.In")}(required=false)
private transient ${pojo.shortName}Finder ${entityFinder};

  • @${pojo.importType("org.jboss.seam.annotations.In")}
    + @${pojo.importType("org.jboss.seam.annotations.In")}(create=true)
    private transient ${pojo.importType("java.util.ResourceBundle")} resourceBundle;


@${pojo.importType("org.jboss.seam.annotations.Begin")}(join=true)
@@ -57,7 +57,7 @@
</#if> entityManager.persist(instance);
isNew = false;
<#foreach property in pojo.getAllPropertiesIterator()><#if c2h.isManyToOne(property)><#assign getter = "get" + pojo.getPropertyName(property)> if (instance.${getter}()!=null) {

  • instance.${getter}().get${pojo.shortName}s().add(instance);
    + instance.${getter}().get${pojo.shortNamePlural}().add(instance);
    }
    </#if></#foreach> refreshFinder();
    return "edit${pojo.shortName}";
    @@ -72,7 +72,8 @@
    @${pojo.importType("org.jboss.seam.annotations.End")}(ifOutcome="find")
    public String delete() {
    entityManager.remove(instance);
    -<#foreach property in pojo.getAllPropertiesIterator()><#if c2h.isManyToOne(property)><#assign getter = "get" + pojo.getPropertyName(property)> instance.${getter}().get${pojo.shortName}s().remove(instance);
    +<#foreach property in pojo.getAllPropertiesIterator()><#if c2h.isManyToOne(property)><#assign getter = "get" + pojo.getPropertyName(property)>
    + instance.${getter}().get${pojo.shortNamePlural}().remove(instance);
    </#if></#foreach> refreshFinder();
    return doneOutcome;
    }

Environment

None

Activity

Show:

Max Rydahl AndersenSeptember 14, 2006 at 7:25 PM

there is a issue reporting the error elsewhere.

thank you for the patch, but it does not solve the problem completly since
it still assumes what the actual "other side" is instead of locating it and use its proper name.

JarkkoJMay 19, 2006 at 1:55 PM

i was thinking it might no be that clear Yes, this is seam specifc (as the real change is in the seam template).

The case is that when DefaultReverseEngineeringStrategy (foreignKeyToCollectionName() ) creates collections is uses ReverseEngineeringStrategyUtil.simplePluralize to name the getter-method in the entity. Now in the seam template the old way was simply to add "s" when calling the entitys getter. Compared to simplePluralize which uses weird english-only heuristic to determine the name.

instance.${getter}().get${pojo.shortName}s().remove(instance);

ReverseEngineeringStrategyUtil.java
...
static public String simplePluralize(String singular) {
char last = singular.charAt( singular.length()-1 );
switch (last) {
case 'x':
case 's':
singular += "es";
break;
case 'y':
singular = singular.substring( 0, singular.length()-1 ) + "ies";
break;
default:
singular += "s";
}
return singular;
}

btw, just noticed that the patch contains few things which are not related to this issue (but to an other one which is that the messages.properties is not initialized properly):

  • @${pojo.importType("org.jboss.seam.annotations.In")}
    + @${pojo.importType("org.jboss.seam.annotations.In")}(create=true)

Those lines can be removed from the patch.

Max Rydahl AndersenMay 19, 2006 at 1:43 PM

thanks - but what does this patch actually fix ?

the reverse engineering works fine with everything so I assume it is something seam template specific....maybe you have a testcase?

Duplicate

Details

Assignee

Reporter

Patch Reminder (view)

Contributions and patches should be using the GitHub Fork + Pull model

Patch Reminder (edit)

Contributions and patches should be using the GitHub [Fork + Pull model|href="https://help.github.com/articles/using-pull-requests]

Participants

JarkkoJ
Max Rydahl Andersen

Components

Affects versions

Priority

Created May 19, 2006 at 12:42 PM
Updated September 14, 2006 at 7:25 PM
Resolved September 14, 2006 at 7:25 PM