List of usage examples for org.hibernate.mapping ToOne getReferencedEntityName
public String getReferencedEntityName()
From source file:com.github.shyiko.rook.target.hibernate4.fulltextindex.SynchronizationContext.java
License:Apache License
@SuppressWarnings("unchecked") private PrimaryKey resolveForeignPrimaryKey(org.hibernate.mapping.Collection collection, Map<String, IndexingDirective> directivesByEntityNameMap) { Table collectionTable = collection.getCollectionTable(); ToOne element = (ToOne) collection.getElement(); IndexingDirective indexingDirective = directivesByEntityNameMap.get(element.getReferencedEntityName()); if (indexingDirective == null) { return null; }/* w w w. j a va 2 s . co m*/ Collection<String> targetPrimaryKeyColumnNames = new HashSet<String>(); for (Iterator<Column> columnIterator = element.getColumnIterator(); columnIterator.hasNext();) { Column column = columnIterator.next(); targetPrimaryKeyColumnNames.add(column.getName()); } Map<String, Integer> columnIndexByNameMap = new HashMap<String, Integer>(); int index = 0; for (Iterator<Column> columnIterator = collectionTable.getColumnIterator(); columnIterator.hasNext();) { Column column = columnIterator.next(); if (targetPrimaryKeyColumnNames.contains(column.getName())) { columnIndexByNameMap.put(column.getName(), index); } index++; } return new PrimaryKey(indexingDirective.getPrimaryKey(), columnIndexByNameMap); }
From source file:org.beangle.orm.hibernate.tool.DdlGenerator.java
License:Open Source License
private void commentToOne(ToOne toOne, Column column) { String entityName = toOne.getReferencedEntityName(); PersistentClass referClass = configuration.getClassMapping(entityName); if (null != referClass) { column.setComment(referClass.getTable().getComment() + " ID"); }//from w ww . ja va2 s .c o m }
From source file:org.wintersleep.codeviz.uml.model.HibernateModelFactory.java
License:Apache License
private void addRelations(CodeModel model) throws ClassNotFoundException { Iterator<PersistentClass> pci = configuration.getClassMappings(); while (pci.hasNext()) { PersistentClass persistentClass = pci.next(); final ModelClass mc = model.findModelClass(persistentClass.getMappedClass()); Iterator<Property> pi = persistentClass.getPropertyIterator(); while (pi.hasNext()) { Property property = pi.next(); System.out.println(property); Value value = property.getValue(); if (value instanceof ToOne) { ToOne toOne = (ToOne) value; ModelClass toClass = model.findModelClass(Class.forName(toOne.getReferencedEntityName())); RelationEndpoint fromEndpoint = new RelationEndpoint(mc, property.getName()); fromEndpoint.setMinCardinality(toOne.isNullable() ? 0 : 1); RelationEndpoint toEndpoint = new RelationEndpoint(toClass, toOne.getReferencedPropertyName()); toEndpoint.setMinCardinality(0); toEndpoint.setMaxCardinality(RelationEndpoint.MANY_CARDINALITY); if (value instanceof OneToOne) { fromEndpoint.setMaxCardinality(1); } else if (value instanceof ManyToOne) { fromEndpoint.setMaxCardinality(1); }//from ww w. j a va 2 s . c om mc.addRelationTo(fromEndpoint, toEndpoint); } else if (value instanceof OneToMany) { OneToMany oneToMany = (OneToMany) value; oneToMany.getAssociatedClass(); ModelClass toClass = model.findModelClass(oneToMany.getAssociatedClass().getMappedClass()); RelationEndpoint fromEndpoint = new RelationEndpoint(mc, property.getName()); fromEndpoint.setMinCardinality(0); fromEndpoint.setMaxCardinality(RelationEndpoint.MANY_CARDINALITY); RelationEndpoint toEndpoint = new RelationEndpoint(toClass, "TODO other"); toEndpoint.setMinCardinality(oneToMany.isNullable() ? 0 : 1); toEndpoint.setMaxCardinality(1); mc.addRelationTo(fromEndpoint, toEndpoint); } } } }