List of usage examples for org.hibernate.boot.spi InFlightMetadataCollector addSecondPass
void addSecondPass(SecondPass secondPass);
From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
/** * First pass to bind collection to Hibernate metamodel, sets up second pass * * @param property The GrailsDomainClassProperty instance * @param collection The collection//from www . ja v a 2s . c o m * @param owner The owning persistent class * @param mappings The Hibernate mappings instance * @param path */ protected void bindCollection(ToMany property, Collection collection, PersistentClass owner, InFlightMetadataCollector mappings, String path, String sessionFactoryBeanName) { // set role String propertyName = getNameForPropertyAndPath(property, path); collection.setRole(qualify(property.getOwner().getName(), propertyName)); PropertyConfig pc = getPropertyConfig(property); // configure eager fetching final FetchMode fetchMode = pc.getFetchMode(); if (fetchMode == FetchMode.JOIN) { collection.setFetchMode(FetchMode.JOIN); } else if (pc.getFetchMode() != null) { collection.setFetchMode(pc.getFetchMode()); } else { collection.setFetchMode(FetchMode.DEFAULT); } if (pc.getCascade() != null) { collection.setOrphanDelete(pc.getCascade().equals(CASCADE_ALL_DELETE_ORPHAN)); } // if it's a one-to-many mapping if (shouldBindCollectionWithForeignKey(property)) { OneToMany oneToMany = new OneToMany(mappings, collection.getOwner()); collection.setElement(oneToMany); bindOneToMany((org.grails.datastore.mapping.model.types.OneToMany) property, oneToMany, mappings); } else { bindCollectionTable(property, mappings, collection, owner.getTable(), sessionFactoryBeanName); if (!property.isOwningSide()) { collection.setInverse(true); } } if (pc.getBatchSize() != null) { collection.setBatchSize(pc.getBatchSize()); } // set up second pass if (collection instanceof org.hibernate.mapping.Set) { mappings.addSecondPass( new GrailsCollectionSecondPass(property, mappings, collection, sessionFactoryBeanName)); } else if (collection instanceof org.hibernate.mapping.List) { mappings.addSecondPass(new ListSecondPass(property, mappings, collection, sessionFactoryBeanName)); } else if (collection instanceof org.hibernate.mapping.Map) { mappings.addSecondPass(new MapSecondPass(property, mappings, collection, sessionFactoryBeanName)); } else { // Collection -> Bag mappings.addSecondPass( new GrailsCollectionSecondPass(property, mappings, collection, sessionFactoryBeanName)); } }