Changeset 1887

Show
Ignore:
Timestamp:
05/15/09 14:42:55 (3 years ago)
Author:
eitan
Message:

fix for possible duplicate column name in hibernate mapping

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • jmatter-complet/trunk/jmatter/src/com/u2d/persist/HBMMaker.java

    r1867 r1887  
    4141   private Document _doc; 
    4242   private boolean _joinedSubclass = false; 
    43     
     43 
    4444   public HBMMaker(Class clazz) 
    4545   { 
     
    582582            else 
    583583            { 
    584                propElem.addAttribute("column", prefix + "_" + field.name()); 
     584               addColumnAttribute(propElem, prefix, field); 
    585585            } 
    586586         } 
     
    605605      addAccessAttribute(propElem); 
    606606      return propElem; 
     607   } 
     608 
     609   private Set<String> colNames = new HashSet<String>(); 
     610   /* ensure unique column names */ 
     611   private void addColumnAttribute(Element propElem, String prefix, Field field) 
     612   { 
     613      String colName = String.format("%s_%s", prefix, field.name()); 
     614      int i=2; 
     615      while (colNames.contains(colName)) 
     616      { 
     617         colName = String.format("%s%d_%s", prefix, i++, field.name()); 
     618      } 
     619      propElem.addAttribute("column", colName); 
     620      colNames.add(colName); 
    607621   } 
    608622