in grails-datastore-gorm-hibernate/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java [1867:1990]
protected void createClassProperties(HibernatePersistentEntity domainClass, PersistentClass persistentClass,
InFlightMetadataCollector mappings, String sessionFactoryBeanName) {
final List<PersistentProperty> persistentProperties = domainClass.getPersistentProperties();
Table table = persistentClass.getTable();
Mapping gormMapping = domainClass.getMapping().getMappedForm();
if (gormMapping != null) {
table.setComment(gormMapping.getComment());
}
List<Embedded> embedded = new ArrayList<>();
for (PersistentProperty currentGrailsProp : persistentProperties) {
// if its inherited skip
if (currentGrailsProp.isInherited()) {
continue;
}
if(currentGrailsProp.getName().equals(GormProperties.VERSION) ) continue;
if (isCompositeIdProperty(gormMapping, currentGrailsProp)) continue;
if (isIdentityProperty(gormMapping, currentGrailsProp)) continue;
if (LOG.isDebugEnabled()) {
LOG.debug("[GrailsDomainBinder] Binding persistent property [" + currentGrailsProp.getName() + "]");
}
Value value = null;
// see if it's a collection type
CollectionType collectionType = CT.collectionTypeForClass(currentGrailsProp.getType());
Class<?> userType = getUserType(currentGrailsProp);
if (userType != null && !UserCollectionType.class.isAssignableFrom(userType)) {
if (LOG.isDebugEnabled()) {
LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName() + "] as SimpleValue");
}
value = new SimpleValue(metadataBuildingContext, table);
bindSimpleValue(currentGrailsProp, null, (SimpleValue) value, EMPTY_PATH, mappings, sessionFactoryBeanName);
}
else if (collectionType != null) {
String typeName = getTypeName(currentGrailsProp, getPropertyConfig(currentGrailsProp),gormMapping);
if ("serializable".equals(typeName)) {
value = new SimpleValue(metadataBuildingContext, table);
bindSimpleValue(typeName, (SimpleValue) value, currentGrailsProp.isNullable(),
getColumnNameForPropertyAndPath(currentGrailsProp, EMPTY_PATH, null, sessionFactoryBeanName), mappings);
}
else {
// create collection
Collection collection = collectionType.create((ToMany) currentGrailsProp, persistentClass,
EMPTY_PATH, mappings, sessionFactoryBeanName);
mappings.addCollectionBinding(collection);
value = collection;
}
}
else if (currentGrailsProp.getType().isEnum()) {
value = new SimpleValue(metadataBuildingContext, table);
bindEnumType(currentGrailsProp, (SimpleValue) value, EMPTY_PATH, sessionFactoryBeanName);
}
else if(currentGrailsProp instanceof Association) {
Association association = (Association) currentGrailsProp;
if (currentGrailsProp instanceof org.grails.datastore.mapping.model.types.ManyToOne) {
if (LOG.isDebugEnabled())
LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName() + "] as ManyToOne");
value = new ManyToOne(metadataBuildingContext, table);
bindManyToOne((Association) currentGrailsProp, (ManyToOne) value, EMPTY_PATH, mappings, sessionFactoryBeanName);
}
else if (currentGrailsProp instanceof org.grails.datastore.mapping.model.types.OneToOne && userType == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName() + "] as OneToOne");
}
final boolean isHasOne = isHasOne(association);
if (isHasOne && !association.isBidirectional()) {
throw new MappingException("hasOne property [" + currentGrailsProp.getOwner().getName() +
"." + currentGrailsProp.getName() + "] is not bidirectional. Specify the other side of the relationship!");
}
else if (canBindOneToOneWithSingleColumnAndForeignKey((Association) currentGrailsProp)) {
value = new OneToOne(metadataBuildingContext, table, persistentClass);
bindOneToOne((org.grails.datastore.mapping.model.types.OneToOne) currentGrailsProp, (OneToOne) value, EMPTY_PATH, sessionFactoryBeanName);
}
else {
if (isHasOne && association.isBidirectional()) {
value = new OneToOne(metadataBuildingContext, table, persistentClass);
bindOneToOne((org.grails.datastore.mapping.model.types.OneToOne) currentGrailsProp, (OneToOne) value, EMPTY_PATH, sessionFactoryBeanName);
}
else {
value = new ManyToOne(metadataBuildingContext, table);
bindManyToOne((Association) currentGrailsProp, (ManyToOne) value, EMPTY_PATH, mappings, sessionFactoryBeanName);
}
}
}
else if (currentGrailsProp instanceof Embedded) {
embedded.add((Embedded)currentGrailsProp);
continue;
}
}
// work out what type of relationship it is and bind value
else {
if (LOG.isDebugEnabled()) {
LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName() + "] as SimpleValue");
}
value = new SimpleValue(metadataBuildingContext, table);
bindSimpleValue(currentGrailsProp, null, (SimpleValue) value, EMPTY_PATH, mappings, sessionFactoryBeanName);
}
if (value != null) {
Property property = createProperty(value, persistentClass, currentGrailsProp, mappings);
persistentClass.addProperty(property);
}
}
for (Embedded association : embedded) {
Value value = new Component(metadataBuildingContext, persistentClass);
bindComponent((Component) value, association, true, mappings, sessionFactoryBeanName);
Property property = createProperty(value, persistentClass, association, mappings);
persistentClass.addProperty(property);
}
bindNaturalIdentifier(table, gormMapping, persistentClass);
}