* Return the type that represents the type of the id.
* @return type of id
*/
public Type<?> getIdType() {
// NOTE: This code is another good reason to abstract out a PKPolicy on the descriptor
CMPPolicy cmpPolicy = getDescriptor().getCMPPolicy();
if (null == cmpPolicy) {
// Composite key support (IE: @EmbeddedId)
List<DatabaseMapping> pkMappings = getDescriptor().getObjectBuilder().getPrimaryKeyMappings();
// Check the primaryKeyFields on the descriptor - for MappedSuperclass pseudo-Descriptors
if(pkMappings.isEmpty()) {
// Search the mappings for Id mappings
for(DatabaseMapping aMapping : getDescriptor().getMappings()) {
if(aMapping.isJPAId()) {
// get the attribute Id (declared or not)
Attribute anAttribute = this.getAttribute(aMapping.getAttributeName());
if(anAttribute != null) {
return this.getMetamodel().getType(anAttribute.getJavaType());
}
}
}
}
if (pkMappings.size() == 1) {
Class aClass = pkMappings.get(0).getAttributeClassification(); // null for OneToOneMapping
// lookup class in our types map
return this.metamodel.getType(aClass);
}
}
// Single Key support using any Java class - built in or user defined
// There already is an instance of the PKclass on the policy
if (cmpPolicy.isCMP3Policy()) {
// BasicType, EntityType or IdentifiableType are handled here, lookup the class in the types map and create a wrapper if it does not exist yet
return this.metamodel.getType(((CMP3Policy) cmpPolicy).getPKClass());
}
// Non-specification mandated exception
throw new IllegalArgumentException(ExceptionLocalization.buildMessage(