Java Code Examples for javax.persistence.InheritanceType#SINGLE_TABLE

The following examples show how to use javax.persistence.InheritanceType#SINGLE_TABLE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InheritanceFactory.java    From celerio with Apache License 2.0 6 votes vote down vote up
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().hasEntityBySchemaAndTableName(entity.getTable().getSchemaName(), entity.getTable().getName())) {
            InheritanceType inheritanceType = entity.getInheritance().getStrategy();

            if (inheritanceType == InheritanceType.SINGLE_TABLE) {
                if (entity.isRoot()) {
                    config.getProject().putEntity(entity);
                }
            } else if (inheritanceType == InheritanceType.JOINED || inheritanceType == InheritanceType.TABLE_PER_CLASS) {
                config.getProject().putEntity(entity);
            } else {
                log.warning("Invalid case, there should be an inheritance type");
            }
        }
    }
}
 
Example 2
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private Inheritance getInheritance(Element tree, XMLContext.Default defaults) {
	Element element = tree != null ? tree.element( "inheritance" ) : null;
	if ( element != null ) {
		AnnotationDescriptor ad = new AnnotationDescriptor( Inheritance.class );
		Attribute attr = element.attribute( "strategy" );
		InheritanceType strategy = InheritanceType.SINGLE_TABLE;
		if ( attr != null ) {
			String value = attr.getValue();
			if ( "SINGLE_TABLE".equals( value ) ) {
				strategy = InheritanceType.SINGLE_TABLE;
			}
			else if ( "JOINED".equals( value ) ) {
				strategy = InheritanceType.JOINED;
			}
			else if ( "TABLE_PER_CLASS".equals( value ) ) {
				strategy = InheritanceType.TABLE_PER_CLASS;
			}
			else {
				throw new AnnotationException(
						"Unknown InheritanceType in XML: " + value + " (" + SCHEMA_VALIDATION + ")"
				);
			}
		}
		ad.setValue( "strategy", strategy );
		return AnnotationFactory.create( ad );
	}
	else if ( defaults.canUseJavaAnnotations() ) {
		return getPhysicalAnnotation( Inheritance.class );
	}
	else {
		return null;
	}
}
 
Example 3
Source File: BaseEntityManagerFunctionalTestCase.java    From google-cloud-spanner-hibernate with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static boolean isSingleTable(Class<?> entity) {
  Inheritance inheritance = entity.getSuperclass().getAnnotation(Inheritance.class);
  return inheritance != null && inheritance.strategy() == InheritanceType.SINGLE_TABLE;
}