use of org.hibernate.persister.entity.EntityPersister in project hibernate-orm by hibernate.
the class DefaultMergeEventListener method entityIsTransient.
protected void entityIsTransient(MergeEvent event, Map copyCache) {
LOG.trace("Merging transient instance");
final Object entity = event.getEntity();
final EventSource source = event.getSession();
final String entityName = event.getEntityName();
final EntityPersister persister = source.getEntityPersister(entityName, entity);
final Serializable id = persister.hasIdentifierProperty() ? persister.getIdentifier(entity, source) : null;
if (copyCache.containsKey(entity)) {
persister.setIdentifier(copyCache.get(entity), id, source);
} else {
//beforeQuery cascade!
((MergeContext) copyCache).put(entity, source.instantiate(persister, id), true);
}
final Object copy = copyCache.get(entity);
// cascade first, so that all unsaved objects get their
// copy created beforeQuery we actually copy
//cascadeOnMerge(event, persister, entity, copyCache, Cascades.CASCADE_BEFORE_MERGE);
super.cascadeBeforeSave(source, persister, entity, copyCache);
copyValues(persister, entity, copy, source, copyCache, ForeignKeyDirection.FROM_PARENT);
saveTransientEntity(copy, entityName, event.getRequestedId(), source, copyCache);
// cascade first, so that all unsaved objects get their
// copy created beforeQuery we actually copy
super.cascadeAfterSave(source, persister, entity, copyCache);
copyValues(persister, entity, copy, source, copyCache, ForeignKeyDirection.TO_PARENT);
event.setResult(copy);
}
use of org.hibernate.persister.entity.EntityPersister in project hibernate-orm by hibernate.
the class FromElementFactory method addFromElement.
FromElement addFromElement() throws SemanticException {
final FromClause parentFromClause = fromClause.getParentFromClause();
if (parentFromClause != null) {
// Look up class name using the first identifier in the path.
final String pathAlias = PathHelper.getAlias(path);
final FromElement parentFromElement = parentFromClause.getFromElement(pathAlias);
if (parentFromElement != null) {
return createFromElementInSubselect(path, pathAlias, parentFromElement, classAlias);
}
}
final EntityPersister entityPersister = fromClause.getSessionFactoryHelper().requireClassPersister(path);
final FromElement elem = createAndAddFromElement(path, classAlias, entityPersister, (EntityType) ((Queryable) entityPersister).getType(), null);
// Add to the query spaces.
fromClause.getWalker().addQuerySpaces(entityPersister.getQuerySpaces());
return elem;
}
use of org.hibernate.persister.entity.EntityPersister in project hibernate-orm by hibernate.
the class FromElementFactory method createFromElementInSubselect.
private FromElement createFromElementInSubselect(String path, String pathAlias, FromElement parentFromElement, String classAlias) throws SemanticException {
LOG.debugf("createFromElementInSubselect() : path = %s", path);
// Create an DotNode AST for the path and resolve it.
FromElement fromElement = evaluateFromElementPath(path, classAlias);
EntityPersister entityPersister = fromElement.getEntityPersister();
// If the first identifier in the path refers to the class alias (not the class name), then this
// is a correlated subselect. If it's a correlated sub-select, use the existing table alias. Otherwise
// generate a new one.
String tableAlias = null;
boolean correlatedSubselect = pathAlias.equals(parentFromElement.getClassAlias());
if (correlatedSubselect) {
tableAlias = fromElement.getTableAlias();
} else {
tableAlias = null;
}
// If the from element isn't in the same clause, create a new from element.
if (fromElement.getFromClause() != fromClause) {
LOG.debug("createFromElementInSubselect() : creating a new FROM element...");
fromElement = createFromElement(entityPersister);
initializeAndAddFromElement(fromElement, path, classAlias, entityPersister, (EntityType) ((Queryable) entityPersister).getType(), tableAlias);
}
LOG.debugf("createFromElementInSubselect() : %s -> %s", path, fromElement);
return fromElement;
}
use of org.hibernate.persister.entity.EntityPersister in project hibernate-orm by hibernate.
the class FromElementFactory method createJoin.
private FromElement createJoin(String entityClass, String tableAlias, JoinSequence joinSequence, EntityType type, boolean manyToMany) throws SemanticException {
// origin, path, implied, columns, classAlias,
EntityPersister entityPersister = fromClause.getSessionFactoryHelper().requireClassPersister(entityClass);
FromElement destination = createAndAddFromElement(entityClass, classAlias, entityPersister, type, tableAlias);
return initializeJoin(path, destination, joinSequence, getColumns(), origin, manyToMany);
}
use of org.hibernate.persister.entity.EntityPersister in project hibernate-orm by hibernate.
the class FromElementFactory method createEntityJoin.
public FromElement createEntityJoin(String entityClass, String tableAlias, JoinSequence joinSequence, boolean fetchFlag, boolean inFrom, EntityType type, String role, String joinPath) throws SemanticException {
FromElement elem = createJoin(entityClass, tableAlias, joinSequence, type, false);
elem.setFetch(fetchFlag);
if (joinPath != null) {
elem.applyTreatAsDeclarations(fromClause.getWalker().getTreatAsDeclarationsByPath(joinPath));
}
EntityPersister entityPersister = elem.getEntityPersister();
int numberOfTables = entityPersister.getQuerySpaces().length;
if (numberOfTables > 1 && implied && !elem.useFromFragment()) {
LOG.debug("createEntityJoin() : Implied multi-table entity join");
elem.setUseFromFragment(true);
}
// flag on the FromElement that indicates that it was implied in the FROM clause itself.
if (implied && inFrom) {
joinSequence.setUseThetaStyle(false);
elem.setUseFromFragment(true);
elem.setImpliedInFromClause(true);
}
if (elem.getWalker().isSubQuery()) {
// and 'elem' represents an implicit join
if (elem.getFromClause() != elem.getOrigin().getFromClause() || // ( implied && DotNode.useThetaStyleImplicitJoins ) ) {
DotNode.useThetaStyleImplicitJoins) {
// the "root from-element" in correlated subqueries do need this piece
elem.setType(FROM_FRAGMENT);
joinSequence.setUseThetaStyle(true);
elem.setUseFromFragment(false);
}
}
elem.setRole(role);
return elem;
}
Aggregations