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());
}
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();
}
Aggregations