use of javax.persistence.metamodel.EntityType in project hibernate-orm by hibernate.
the class PluralAttributePath method locateNearestSubclassEntity.
private EntityType locateNearestSubclassEntity(MappedSuperclassType mappedSuperclassType, EntityType entityTypeTop) {
EntityType entityTypeNearestDeclaringType = entityTypeTop;
IdentifiableType superType = entityTypeNearestDeclaringType.getSupertype();
while (superType != mappedSuperclassType) {
if (superType == null) {
throw new IllegalStateException(String.format("Cannot determine nearest EntityType extending mapped superclass [%s] starting from [%s]; a supertype of [%s] is null", mappedSuperclassType.getJavaType().getName(), entityTypeTop.getJavaType().getName(), entityTypeTop.getJavaType().getName()));
}
if (superType.getPersistenceType() == Type.PersistenceType.ENTITY) {
entityTypeNearestDeclaringType = (EntityType) superType;
}
superType = superType.getSupertype();
}
return entityTypeNearestDeclaringType;
}
use of javax.persistence.metamodel.EntityType in project hibernate-orm by hibernate.
the class MetamodelImpl method applyNamedEntityGraphs.
@SuppressWarnings("unchecked")
private void applyNamedEntityGraphs(java.util.Collection<NamedEntityGraphDefinition> namedEntityGraphs) {
for (NamedEntityGraphDefinition definition : namedEntityGraphs) {
log.debugf("Applying named entity graph [name=%s, entity-name=%s, jpa-entity-name=%s", definition.getRegisteredName(), definition.getEntityName(), definition.getJpaEntityName());
final EntityType entityType = entity(definition.getEntityName());
if (entityType == null) {
throw new IllegalArgumentException("Attempted to register named entity graph [" + definition.getRegisteredName() + "] for unknown entity [" + definition.getEntityName() + "]");
}
final EntityGraphImpl entityGraph = new EntityGraphImpl(definition.getRegisteredName(), entityType, this.getSessionFactory());
final NamedEntityGraph namedEntityGraph = definition.getAnnotation();
if (namedEntityGraph.includeAllAttributes()) {
for (Object attributeObject : entityType.getAttributes()) {
entityGraph.addAttributeNodes((Attribute) attributeObject);
}
}
if (namedEntityGraph.attributeNodes() != null) {
applyNamedAttributeNodes(namedEntityGraph.attributeNodes(), namedEntityGraph, entityGraph);
}
entityGraphMap.put(definition.getRegisteredName(), entityGraph);
}
}
use of javax.persistence.metamodel.EntityType in project uPortal by Jasig.
the class BaseJpaDaoTest method deleteAllEntities.
/** Deletes ALL entities from the database */
@After
public final void deleteAllEntities() {
final EntityManager entityManager = getEntityManager();
final EntityManagerFactory entityManagerFactory = entityManager.getEntityManagerFactory();
final Metamodel metamodel = entityManagerFactory.getMetamodel();
Set<EntityType<?>> entityTypes = new LinkedHashSet<EntityType<?>>(metamodel.getEntities());
do {
final Set<EntityType<?>> failedEntitieTypes = new HashSet<EntityType<?>>();
for (final EntityType<?> entityType : entityTypes) {
final String entityClassName = entityType.getBindableJavaType().getName();
try {
this.executeInTransaction(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
logger.trace("Purging all: " + entityClassName);
final Query query = entityManager.createQuery("SELECT e FROM " + entityClassName + " AS e");
final List<?> entities = query.getResultList();
logger.trace("Found " + entities.size() + " " + entityClassName + " to delete");
for (final Object entity : entities) {
entityManager.remove(entity);
}
}
});
} catch (DataIntegrityViolationException e) {
logger.trace("Failed to delete " + entityClassName + ". Must be a dependency of another entity");
failedEntitieTypes.add(entityType);
}
}
entityTypes = failedEntitieTypes;
} while (!entityTypes.isEmpty());
//Reset all spring managed mocks after every test
MockitoFactoryBean.resetAllMocks();
}
Aggregations