Je suis en train de configurer des classes Hibernate non par XML/Annotation, mais en utilisant leur API de programmation:Mise en veille prolongée - configuration Programmatic
Mappings mappings = configuration.createMappings();
mappings.addClass(...);
Un exemple d'addition de la colonne:
public void addColumn(String colName, String accessorName, NullableType type)
{
if(this._table == null)
{
return;
}
Column column = new Column(colName);
// this._table.addColumn(column);
Property prop = new Property();
prop.setName(accessorName);
SimpleValue simpleValue = new SimpleValue();
simpleValue.setTypeName(type.getName());
simpleValue.addColumn(column);
simpleValue.setTable(_table);
prop.setValue(simpleValue);
this._rootClass.addProperty(prop);
}
Cela fonctionne, jusqu'à la première fois j'ai besoin d'ajouter une colonne avec un nom qui existe déjà. Son pas ajouter la même colonne à la même table, ce sont deux tables différentes, mais néanmoins, je reçois
ERROR: java.lang.NullPointerException
at
org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:711)
J'ai vérifié contre le code source (j'utilise Hibernate 3.3.1 GA) et il est une ligne PersistentClass, ligne 711:
protected void checkColumnDuplication() {
HashSet cols = new HashSet(); <=========After this line 'cols' already contain data!
if (getIdentifierMapper() == null) {
//an identifier mapper => getKey will be included in the getNonDuplicatedPropertyIterator()
//and checked later, so it needs to be excluded
checkColumnDuplication(cols, getKey().getColumnIterator());
}
checkColumnDuplication(cols, getDiscriminatorColumnIterator());
checkPropertyColumnDuplication(cols, getNonDuplicatedPropertyIterator());
Iterator iter = getJoinIterator();
while (iter.hasNext()) {
cols.clear();
Join join = (Join) iter.next();
checkColumnDuplication(cols, join.getKey().getColumnIterator());
checkPropertyColumnDuplication(cols, join.getPropertyIterator());
}
}
Quelqu'un at-il essayer de le configurer comme ça, eu le même problème ...
Merci à l'avance