javax.persistence.IdClass Java Examples

The following examples show how to use javax.persistence.IdClass. 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: InheritanceState.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public XClass getClassWithIdClass(boolean evenIfSubclass) {
	if ( !evenIfSubclass && hasParents() ) {
		return null;
	}
	if ( clazz.isAnnotationPresent( IdClass.class ) ) {
		return clazz;
	}
	else {
		InheritanceState state = InheritanceState.getSuperclassInheritanceState( clazz, inheritanceStatePerClass );
		if ( state != null ) {
			return state.getClassWithIdClass( true );
		}
		else {
			return null;
		}
	}
}
 
Example #2
Source File: MybatisReflectionEntityInformation.java    From spring-data-mybatis with Apache License 2.0 6 votes vote down vote up
public MybatisReflectionEntityInformation(Class<T> domainClass) {
	super(domainClass);

	IdClass idClass = domainClass.getAnnotation(IdClass.class);
	if (null != idClass) {
		this.idClass = idClass.value();
	}
	else {
		for (Class<? extends Annotation> annotation : MybatisPersistentPropertyImpl.ID_ANNOTATIONS) {
			AnnotationDetectionFieldCallback callback = new AnnotationDetectionFieldCallback(
					annotation);
			ReflectionUtils.doWithFields(domainClass, callback);

			try {
				this.field = callback.getRequiredField();
			}
			catch (IllegalStateException o_O) {

			}
			if (null != this.field) {
				ReflectionUtils.makeAccessible(this.field);
				break;
			}
		}
	}
}
 
Example #3
Source File: EntityUtils.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Class<? extends Serializable> primaryKeyClass(Class<?> entityClass)
{
    if (entityClass.isAnnotationPresent(IdClass.class))
    {
        return entityClass.getAnnotation(IdClass.class).value(); // Serializablity isn't required, could cause
                                                                 // problems
    }
    Class clazz = PersistenceUnitDescriptorProvider.getInstance().primaryKeyIdClass(entityClass);
    if (clazz != null)
    {
        return clazz;
    }
    Property<Serializable> property = primaryKeyProperty(entityClass);
    return property.getJavaClass();
}
 
Example #4
Source File: AnnotationBinder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isIdClassPkOfTheAssociatedEntity(
		InheritanceState.ElementsToProcess elementsToProcess,
		XClass compositeClass,
		PropertyData inferredData,
		PropertyData baseInferredData,
		AccessType propertyAccessor,
		Map<XClass, InheritanceState> inheritanceStatePerClass,
		MetadataBuildingContext context) {
	if ( elementsToProcess.getIdPropertyCount() == 1 ) {
		final PropertyData idPropertyOnBaseClass = getUniqueIdPropertyFromBaseClass(
				inferredData,
				baseInferredData,
				propertyAccessor,
				context
		);
		final InheritanceState state = inheritanceStatePerClass.get( idPropertyOnBaseClass.getClassOrElement() );
		if ( state == null ) {
			return false; //while it is likely a user error, let's consider it is something that might happen
		}
		final XClass associatedClassWithIdClass = state.getClassWithIdClass( true );
		if ( associatedClassWithIdClass == null ) {
			//we cannot know for sure here unless we try and find the @EmbeddedId
			//Let's not do this thorough checking but do some extra validation
			final XProperty property = idPropertyOnBaseClass.getProperty();
			return property.isAnnotationPresent( ManyToOne.class )
					|| property.isAnnotationPresent( OneToOne.class );

		}
		else {
			final XClass idClass = context.getBootstrapContext().getReflectionManager().toXClass(
					associatedClassWithIdClass.getAnnotation( IdClass.class ).value()
			);
			return idClass.equals( compositeClass );
		}
	}
	else {
		return false;
	}
}
 
Example #5
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private IdClass getIdClass(Element tree, XMLContext.Default defaults) {
	Element element = tree == null ? null : tree.element( "id-class" );
	if ( element != null ) {
		Attribute attr = element.attribute( "class" );
		if ( attr != null ) {
			AnnotationDescriptor ad = new AnnotationDescriptor( IdClass.class );
			Class clazz;
			try {
				clazz = classLoaderAccess.classForName( XMLContext.buildSafeClassName( attr.getValue(), defaults )
				);
			}
			catch ( ClassLoadingException e ) {
				throw new AnnotationException( "Unable to find id-class: " + attr.getValue(), e );
			}
			ad.setValue( "value", clazz );
			return AnnotationFactory.create( ad );
		}
		else {
			throw new AnnotationException( "id-class without class. " + SCHEMA_VALIDATION );
		}
	}
	else if ( defaults.canUseJavaAnnotations() ) {
		return getPhysicalAnnotation( IdClass.class );
	}
	else {
		return null;
	}
}
 
Example #6
Source File: InspectionResultProcessor.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
private boolean shouldOmitPropertyWithCompositeKey(Map<String, String> propertyAttributes)
{
   // Extract simple type name of the relationship types
   boolean isManyToOneRel = Boolean.parseBoolean(propertyAttributes.get("many-to-one"));
   boolean isOneToOneRel = Boolean.parseBoolean(propertyAttributes.get("one-to-one"));
   boolean isNToManyRel = Boolean.parseBoolean(propertyAttributes.get("n-to-many"));
   if (isManyToOneRel || isNToManyRel || isOneToOneRel)
   {
      String rightHandSideType;
      // Obtain the class name of the other/right-hand side of the relationship.
      if (isOneToOneRel || isManyToOneRel)
      {
         rightHandSideType = propertyAttributes.get("type");
      }
      else
      {
         rightHandSideType = propertyAttributes.get("parameterized-type");
      }
      JavaClassSource javaClass = getJavaClass(rightHandSideType);
      for (Member<?> member : javaClass.getMembers())
      {
         // FORGEPLUGINS-120 Ensure that properties with composite keys are detected and omitted from generation
         if (member.hasAnnotation(Id.class) && !javaClass.hasAnnotation(IdClass.class))
         {
            return false;
         }
         if (member.hasAnnotation(EmbeddedId.class))
         {
            return true;
         }
      }
   }
   return false;
}
 
Example #7
Source File: DefaultJpaEntityMetadata.java    From ueboot with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static Class<?> fallbackIdTypeLookup(IdentifiableType<?> type) {

            IdClass annotation = AnnotationUtils.findAnnotation(type.getJavaType(), IdClass.class);
            return annotation == null ? null : annotation.value();
        }