use of org.hibernate.type.EntityType 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.EntityType in project hibernate-orm by hibernate.
the class PathExpressionParser method token.
public void token(String token, QueryTranslatorImpl q) throws QueryException {
if (token != null) {
path.append(token);
}
String alias = q.getPathAlias(path.toString());
if (alias != null) {
//reset the dotcount (but not the path)
reset(q);
//afterQuery reset!
currentName = alias;
currentPropertyMapping = q.getPropertyMapping(currentName);
if (!ignoreInitialJoin) {
JoinSequence ojf = q.getPathJoin(path.toString());
try {
//afterQuery reset!
joinSequence.addCondition(ojf.toJoinFragment(q.getEnabledFilters(), true).toWhereFragmentString());
} catch (MappingException me) {
throw new QueryException(me);
}
// we don't need to worry about any condition in the ON clause
// here (toFromFragmentString), since anything in the ON condition
// is already applied to the whole query
}
} else if (".".equals(token)) {
dotcount++;
} else {
if (dotcount == 0) {
if (!continuation) {
if (!q.isName(token)) {
throw new QueryException("undefined alias: " + token);
}
currentName = token;
currentPropertyMapping = q.getPropertyMapping(currentName);
}
} else if (dotcount == 1) {
if (currentName != null) {
currentProperty = token;
} else if (collectionName != null) {
//processCollectionProperty(token, q.getCollectionPersister(collectionRole), collectionName);
continuation = false;
} else {
throw new QueryException("unexpected");
}
} else {
// dotcount>=2
// Do the corresponding RHS
Type propertyType = getPropertyType();
if (propertyType == null) {
throw new QueryException("unresolved property: " + path);
}
if (propertyType.isComponentType()) {
dereferenceComponent(token);
} else if (propertyType.isEntityType()) {
if (!isCollectionValued()) {
dereferenceEntity(token, (EntityType) propertyType, q);
}
} else if (propertyType.isCollectionType()) {
dereferenceCollection(token, ((CollectionType) propertyType).getRole(), q);
} else {
if (token != null) {
throw new QueryException("dereferenced: " + path);
}
}
}
}
}
use of org.hibernate.type.EntityType in project hibernate-orm by hibernate.
the class MapKeyEntityFromElement method buildKeyJoin.
public static MapKeyEntityFromElement buildKeyJoin(FromElement collectionFromElement) {
final HqlSqlWalker walker = collectionFromElement.getWalker();
final SessionFactoryHelper sfh = walker.getSessionFactoryHelper();
final SessionFactoryImplementor sf = sfh.getFactory();
final QueryableCollection collectionPersister = collectionFromElement.getQueryableCollection();
final Type indexType = collectionPersister.getIndexType();
if (indexType == null) {
throw new IllegalArgumentException("Given collection is not indexed");
}
if (!indexType.isEntityType()) {
throw new IllegalArgumentException("Given collection does not have an entity index");
}
final EntityType indexEntityType = (EntityType) indexType;
final EntityPersister indexEntityPersister = (EntityPersister) indexEntityType.getAssociatedJoinable(sf);
final String rhsAlias = walker.getAliasGenerator().createName(indexEntityPersister.getEntityName());
final boolean useThetaJoin = collectionFromElement.getJoinSequence().isThetaStyle();
MapKeyEntityFromElement join = new MapKeyEntityFromElement(useThetaJoin);
join.initialize(HqlSqlTokenTypes.JOIN_FRAGMENT, ((Joinable) indexEntityPersister).getTableName());
join.initialize(collectionFromElement.getWalker());
join.initializeEntity(collectionFromElement.getFromClause(), indexEntityPersister.getEntityName(), indexEntityPersister, indexEntityType, "<map-key-join-" + collectionFromElement.getClassAlias() + ">", rhsAlias);
// String[] joinColumns = determineJoinColuns( collectionPersister, joinTableAlias );
// todo : assumes columns, no formulas
String[] joinColumns = collectionPersister.getIndexColumnNames(collectionFromElement.getCollectionTableAlias());
JoinSequence joinSequence = sfh.createJoinSequence(useThetaJoin, indexEntityType, rhsAlias, // JoinType.INNER_JOIN,
collectionFromElement.getJoinSequence().getFirstJoin().getJoinType(), joinColumns);
join.setJoinSequence(joinSequence);
join.setOrigin(collectionFromElement, true);
join.setColumns(joinColumns);
join.setUseFromFragment(collectionFromElement.useFromFragment());
join.setUseWhereFragment(collectionFromElement.useWhereFragment());
walker.addQuerySpaces(indexEntityPersister.getQuerySpaces());
return join;
}
use of org.hibernate.type.EntityType in project hibernate-orm by hibernate.
the class JoinWalker method isJoinedFetchEnabledInMapping.
/**
* Does the mapping, and Hibernate default semantics, specify that
* this association should be fetched by outer joining
*/
protected boolean isJoinedFetchEnabledInMapping(FetchMode config, AssociationType type) throws MappingException {
if (!type.isEntityType() && !type.isCollectionType()) {
return false;
} else {
if (config == FetchMode.JOIN) {
return true;
}
if (config == FetchMode.SELECT) {
return false;
}
if (type.isEntityType()) {
//TODO: look at the owning property and check that it
// isn't lazy (by instrumentation)
EntityType entityType = (EntityType) type;
EntityPersister persister = getFactory().getEntityPersister(entityType.getAssociatedEntityName());
return !persister.hasProxy();
} else {
return false;
}
}
}
use of org.hibernate.type.EntityType in project hibernate-orm by hibernate.
the class Loader method registerNonExists.
/**
* For missing objects associated by one-to-one with another object in the
* result set, register the fact that the the object is missing with the
* session.
*/
private void registerNonExists(final EntityKey[] keys, final Loadable[] persisters, final SharedSessionContractImplementor session) {
final int[] owners = getOwners();
if (owners != null) {
EntityType[] ownerAssociationTypes = getOwnerAssociationTypes();
for (int i = 0; i < keys.length; i++) {
int owner = owners[i];
if (owner > -1) {
EntityKey ownerKey = keys[owner];
if (keys[i] == null && ownerKey != null) {
final PersistenceContext persistenceContext = session.getPersistenceContext();
/*final boolean isPrimaryKey;
final boolean isSpecialOneToOne;
if ( ownerAssociationTypes == null || ownerAssociationTypes[i] == null ) {
isPrimaryKey = true;
isSpecialOneToOne = false;
}
else {
isPrimaryKey = ownerAssociationTypes[i].getRHSUniqueKeyPropertyName()==null;
isSpecialOneToOne = ownerAssociationTypes[i].getLHSPropertyName()!=null;
}*/
//TODO: can we *always* use the "null property" approach for everything?
/*if ( isPrimaryKey && !isSpecialOneToOne ) {
persistenceContext.addNonExistantEntityKey(
new EntityKey( ownerKey.getIdentifier(), persisters[i], session.getEntityMode() )
);
}
else if ( isSpecialOneToOne ) {*/
boolean isOneToOneAssociation = ownerAssociationTypes != null && ownerAssociationTypes[i] != null && ownerAssociationTypes[i].isOneToOne();
if (isOneToOneAssociation) {
persistenceContext.addNullProperty(ownerKey, ownerAssociationTypes[i].getPropertyName());
}
/*}
else {
persistenceContext.addNonExistantEntityUniqueKey( new EntityUniqueKey(
persisters[i].getEntityName(),
ownerAssociationTypes[i].getRHSUniqueKeyPropertyName(),
ownerKey.getIdentifier(),
persisters[owner].getIdentifierType(),
session.getEntityMode()
) );
}*/
}
}
}
}
}
Aggregations