List of usage examples for org.hibernate.mapping Component setDynamic
public void setDynamic(boolean dynamic)
From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java
License:Open Source License
protected void createPKComposite(Mappings mappings, com.manydesigns.portofino.model.database.Table mdTable, String pkName, RootClass clazz, Table tab, List<com.manydesigns.portofino.model.database.Column> columnPKList) { PrimaryKey primaryKey = new PrimaryKey(); primaryKey.setName(pkName);/* w ww . j a v a 2s . c om*/ primaryKey.setTable(tab); clazz.setEmbeddedIdentifier(true); Component component = new Component(mappings, clazz); component.setDynamic(mdTable.getActualJavaClass() == null); String name; name = mdTable.getQualifiedName(); component.setRoleName(name + ".id"); component.setEmbedded(true); //component.setNodeName("id"); component.setKey(true); component.setNullValue("undefined"); if (!component.isDynamic()) { component.setComponentClassName(mdTable.getJavaClass()); //TODO verificare se non si intende actualJavaClass } boolean hasErrors = false; for (com.manydesigns.portofino.model.database.Column column : columnPKList) { if (column == null) { throw new InternalError("Null column"); } Column col = createColumn(mappings, tab, column); hasErrors = col == null || hasErrors; if (col != null) { primaryKey.addColumn(col); Property prop = createProperty(column, col.getValue()); prop.setCascade("none"); //prop.setPropertyAccessorName("property"); interferisce con il generator pi sotto prop.setPersistentClass(clazz); component.addProperty(prop); //Generator not supported for embedded map identifier //See https://forum.hibernate.org/viewtopic.php?t=945273 //See Component.buildIdentifierGenerator() /*String columnName = column.getColumnName(); PrimaryKeyColumn pkCol = mdTable.getPrimaryKey().findPrimaryKeyColumnByName(columnName); if(pkCol == null) { logger.error("Column without corresponding PrimaryKeyColumn: {}", columnName); hasErrors = true; continue; } Generator generator = pkCol.getGenerator(); setPKColumnGenerator(mappings, clazz, tab, column, value, generator);*/ } } if (hasErrors) { // TODO PAOLO: se la PK non e' buona, tutta la tabella dovrebbe saltare logger.error("Skipping primary key"); return; } tab.setIdentifierValue(component); clazz.setIdentifier(component); clazz.setDiscriminatorValue(name); tab.setPrimaryKey(primaryKey); }
From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java
License:Open Source License
private DependantValue createFKComposite(Mappings mappings, com.manydesigns.portofino.model.database.ForeignKey relationship, com.manydesigns.portofino.model.database.Table manyMDTable, PersistentClass clazzOne, PersistentClass clazzMany, Bag set, Table tableMany, Table tableOne, List<Column> oneColumns, List<Column> manyColumns) { DependantValue dv;/*from www. j a v a2 s. c o m*/ Component component = new Component(mappings, set); component.setDynamic(manyMDTable.getActualJavaClass() == null); component.setEmbedded(true); dv = new DependantValue(mappings, clazzMany.getTable(), component); dv.setNullable(true); dv.setUpdateable(true); for (Reference ref : relationship.getReferences()) { String colToName = ref.getToColumn(); String colToPropertyName = ref.getActualToColumn().getActualPropertyName(); String colFromName = ref.getFromColumn(); Iterator it = tableMany.getColumnIterator(); while (it.hasNext()) { Column col = (Column) it.next(); if (col.getName().equals(colFromName)) { dv.addColumn(col); manyColumns.add(col); break; } } Iterator it2 = tableOne.getColumnIterator(); while (it2.hasNext()) { Column col = (Column) it2.next(); if (col.getName().equals(colToName)) { oneColumns.add(col); break; } } Property refProp; refProp = getRefProperty(clazzOne, colToPropertyName); component.addProperty(refProp); } return dv; }