Example usage for org.hibernate.mapping RootClass hasSubclasses

List of usage examples for org.hibernate.mapping RootClass hasSubclasses

Introduction

In this page you can find the example usage for org.hibernate.mapping RootClass hasSubclasses.

Prototype

public boolean hasSubclasses() 

Source Link

Usage

From source file:org.grails.orm.hibernate.cfg.GrailsAnnotationConfiguration.java

License:Apache License

/**
 * Creates foreign keys for subclass tables that are mapped using table per subclass. Further information is
 * available in the <a href="http://jira.grails.org/browse/GRAILS-7729">JIRA ticket</a>
 *//*from   w ww.  ja v a 2 s.  co  m*/
private void createSubclassForeignKeys() {
    if (subclassForeignKeysCreated) {
        return;
    }

    for (PersistentClass persistentClass : classes.values()) {
        if (persistentClass instanceof RootClass) {
            RootClass rootClass = (RootClass) persistentClass;

            if (rootClass.hasSubclasses()) {
                Iterator subclasses = rootClass.getSubclassIterator();

                while (subclasses.hasNext()) {

                    Object subclass = subclasses.next();

                    // This test ensures that foreign keys will only be created for subclasses that are
                    // mapped using "table per subclass"
                    if (subclass instanceof JoinedSubclass) {
                        JoinedSubclass joinedSubclass = (JoinedSubclass) subclass;
                        joinedSubclass.createForeignKey();
                    }
                }
            }
        }
    }

    subclassForeignKeysCreated = true;
}