Search in sources :

Example 1 with EmbeddedComponentType

use of org.hibernate.type.EmbeddedComponentType in project hibernate-orm by hibernate.

the class DefaultLoadEventListener method checkIdClass.

private void checkIdClass(final EntityPersister persister, final LoadEvent event, final LoadEventListener.LoadType loadType, final Class idClass) {
    // is part of its generally goofy "derived identity" "feature"
    if (persister.getEntityMetamodel().getIdentifierProperty().isEmbedded()) {
        final EmbeddedComponentType dependentIdType = (EmbeddedComponentType) persister.getEntityMetamodel().getIdentifierProperty().getType();
        if (dependentIdType.getSubtypes().length == 1) {
            final Type singleSubType = dependentIdType.getSubtypes()[0];
            if (singleSubType.isEntityType()) {
                final EntityType dependentParentType = (EntityType) singleSubType;
                final Type dependentParentIdType = dependentParentType.getIdentifierOrUniqueKeyType(event.getSession().getFactory());
                if (dependentParentIdType.getReturnedClass().isInstance(event.getEntityId())) {
                    // yep that's what we have...
                    loadByDerivedIdentitySimplePkValue(event, loadType, persister, dependentIdType, event.getSession().getFactory().getEntityPersister(dependentParentType.getAssociatedEntityName()));
                    return;
                }
            }
        }
    }
    throw new TypeMismatchException("Provided id of the wrong type for class " + persister.getEntityName() + ". Expected: " + idClass + ", got " + event.getEntityId().getClass());
}
Also used : EntityType(org.hibernate.type.EntityType) EmbeddedComponentType(org.hibernate.type.EmbeddedComponentType) EntityType(org.hibernate.type.EntityType) EventType(org.hibernate.event.spi.EventType) Type(org.hibernate.type.Type) EmbeddedComponentType(org.hibernate.type.EmbeddedComponentType) TypeMismatchException(org.hibernate.TypeMismatchException)

Example 2 with EmbeddedComponentType

use of org.hibernate.type.EmbeddedComponentType in project hibernate-orm by hibernate.

the class CriteriaTools method identifierPropertyNames.

/**
 * @param sessionFactory Session factory.
 * @param entityName Entity name.
 *
 * @return List of property names representing entity identifier.
 */
private static List<String> identifierPropertyNames(SessionFactoryImplementor sessionFactory, String entityName) {
    final String identifierPropertyName = sessionFactory.getMetamodel().entityPersister(entityName).getIdentifierPropertyName();
    if (identifierPropertyName != null) {
        // Single id.
        return Arrays.asList(identifierPropertyName);
    }
    final Type identifierType = sessionFactory.getMetamodel().entityPersister(entityName).getIdentifierType();
    if (identifierType instanceof EmbeddedComponentType) {
        // Multiple ids.
        final EmbeddedComponentType embeddedComponentType = (EmbeddedComponentType) identifierType;
        return Arrays.asList(embeddedComponentType.getPropertyNames());
    }
    return Collections.emptyList();
}
Also used : RelationType(org.hibernate.envers.internal.entities.RelationType) EmbeddedComponentType(org.hibernate.type.EmbeddedComponentType) Type(org.hibernate.type.Type) EmbeddedComponentType(org.hibernate.type.EmbeddedComponentType)

Aggregations

EmbeddedComponentType (org.hibernate.type.EmbeddedComponentType)2 Type (org.hibernate.type.Type)2 TypeMismatchException (org.hibernate.TypeMismatchException)1 RelationType (org.hibernate.envers.internal.entities.RelationType)1 EventType (org.hibernate.event.spi.EventType)1 EntityType (org.hibernate.type.EntityType)1