Example usage for javax.persistence InheritanceType JOINED

List of usage examples for javax.persistence InheritanceType JOINED

Introduction

In this page you can find the example usage for javax.persistence InheritanceType JOINED.

Prototype

InheritanceType JOINED

To view the source code for javax.persistence InheritanceType JOINED.

Click Source Link

Document

A strategy in which fields that are specific to a subclass are mapped to a separate table than the fields that are common to the parent class, and a join is performed to instantiate the subclass.

Usage

From source file:com.jaxio.celerio.factory.InheritanceFactory.java

private void putEntityByTableNameForEntityWithInheritance() {
    // Attention, for SINGLE_TABLE inheritance strategy, we only put the root entity.

    for (EntityConfig entityConfig : config.getCelerio().getEntityConfigs()) {
        Entity entity = config.getProject().getEntityByName(entityConfig.getEntityName());

        if (entity.hasInheritance() && !config.getProject().hasEntityByTableName(entity.getTableName())) {
            InheritanceType inheritanceType = entity.getInheritance().getStrategy();

            if (inheritanceType == InheritanceType.SINGLE_TABLE) {
                if (entity.isRoot()) {
                    config.getProject().putEntityByTableName(entity);
                }//from www .jav  a2 s  .co m
            } else if (inheritanceType == InheritanceType.JOINED
                    || inheritanceType == InheritanceType.TABLE_PER_CLASS) {
                config.getProject().putEntityByTableName(entity);
            } else {
                log.warning("Invalid case, there should be an inheritance type");
            }
        }
    }
}

From source file:org.castor.cpa.jpa.processors.classprocessors.JPAInheritanceProcessor.java

/**
 * {@inheritDoc}/*  ww  w . j a  v a  2s .c  o  m*/
 * 
 * @see org.castor.core.annotationprocessing.TargetAwareAnnotationProcessor#
 *      processAnnotation(BaseNature, Annotation, AnnotatedElement)
 */
public <I extends BaseNature, A extends Annotation> boolean processAnnotation(final I info, final A annotation,
        final AnnotatedElement target) throws AnnotationTargetException {

    if ((info instanceof JPAClassNature) && (annotation instanceof Inheritance) && (target instanceof Class<?>)
            && (target.isAnnotationPresent(Inheritance.class))) {
        LOG.debug("Processing class annotation " + annotation.toString());

        JPAClassNature jpaClassNature = (JPAClassNature) info;
        Inheritance inheritance = (Inheritance) annotation;
        InheritanceType strategy = inheritance.strategy();

        if (strategy != InheritanceType.JOINED) {
            throw new AnnotationTargetException("InheritanceType not supported: " + strategy.toString());
        }

        jpaClassNature.setInheritanceStrategy(strategy);
        return true;
    }

    return false;
}