use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class SessionImpl method contains.
@Override
public boolean contains(String entityName, Object object) {
checkOpen();
checkTransactionSynchStatus();
if (object == null) {
return false;
}
try {
if (!HibernateProxy.class.isInstance(object) && persistenceContext.getEntry(object) == null) {
// check if it is an entity -> if not throw an exception (per JPA)
try {
getSessionFactory().getMetamodel().entityPersister(entityName);
} catch (HibernateException e) {
throw new IllegalArgumentException("Not an entity [" + entityName + "] : " + object);
}
}
if (object instanceof HibernateProxy) {
//do not use proxiesByKey, since not all
//proxies that point to this session's
//instances are in that collection!
LazyInitializer li = ((HibernateProxy) object).getHibernateLazyInitializer();
if (li.isUninitialized()) {
//the underlying instance will be "contained"
return li.getSession() == this;
} else {
//if it is initialized, see if the underlying
//instance is contained, since we need to
//account for the fact that it might have been
//evicted
object = li.getImplementation();
}
}
// A session is considered to contain an entity only if the entity has
// an entry in the session's persistence context and the entry reports
// that the entity has not been removed
EntityEntry entry = persistenceContext.getEntry(object);
delayedAfterCompletion();
return entry != null && entry.getStatus() != Status.DELETED && entry.getStatus() != Status.GONE;
} catch (MappingException e) {
throw new IllegalArgumentException(e.getMessage(), e);
} catch (RuntimeException e) {
throw exceptionConverter.convert(e);
}
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class SessionImpl method contains.
@Override
public boolean contains(Object object) {
checkOpen();
checkTransactionSynchStatus();
if (object == null) {
return false;
}
try {
if (object instanceof HibernateProxy) {
//do not use proxiesByKey, since not all
//proxies that point to this session's
//instances are in that collection!
LazyInitializer li = ((HibernateProxy) object).getHibernateLazyInitializer();
if (li.isUninitialized()) {
//the underlying instance will be "contained"
return li.getSession() == this;
} else {
//if it is initialized, see if the underlying
//instance is contained, since we need to
//account for the fact that it might have been
//evicted
object = li.getImplementation();
}
}
// A session is considered to contain an entity only if the entity has
// an entry in the session's persistence context and the entry reports
// that the entity has not been removed
EntityEntry entry = persistenceContext.getEntry(object);
delayedAfterCompletion();
if (entry == null) {
if (!HibernateProxy.class.isInstance(object) && persistenceContext.getEntry(object) == null) {
// check if it is even an entity -> if not throw an exception (per JPA)
try {
final String entityName = getEntityNameResolver().resolveEntityName(object);
if (entityName == null) {
throw new IllegalArgumentException("Could not resolve entity-name [" + object + "]");
}
getSessionFactory().getMetamodel().entityPersister(object.getClass());
} catch (HibernateException e) {
throw new IllegalArgumentException("Not an entity [" + object.getClass() + "]", e);
}
}
return false;
} else {
return entry.getStatus() != Status.DELETED && entry.getStatus() != Status.GONE;
}
} catch (MappingException e) {
throw new IllegalArgumentException(e.getMessage(), e);
} catch (RuntimeException e) {
throw exceptionConverter.convert(e);
}
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class CallbackBuilderLegacyImpl method buildCallbacksForEntity.
@Override
public void buildCallbacksForEntity(String entityClassName, CallbackRegistrar callbackRegistrar) {
try {
final XClass entityXClass = reflectionManager.classForName(entityClassName);
final Class entityClass = reflectionManager.toClass(entityXClass);
for (CallbackType callbackType : CallbackType.values()) {
if (callbackRegistrar.hasRegisteredCallbacks(entityClass, callbackType)) {
// this most likely means we have a class mapped multiple times using the hbm.xml
// "entity name" feature
log.debugf("CallbackRegistry reported that Class [%s] already had %s callbacks registered; " + "assuming this means the class was mapped twice " + "(using hbm.xml entity-name support) - skipping subsequent registrations", entityClassName, callbackType.getCallbackAnnotation().getSimpleName());
continue;
}
final Callback[] callbacks = resolveCallbacks(entityXClass, callbackType, reflectionManager);
callbackRegistrar.registerCallbacks(entityClass, callbacks);
}
} catch (ClassLoadingException e) {
throw new MappingException("entity class not found: " + entityClassName, e);
}
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class Collection method getComparator.
public Comparator getComparator() {
if (comparator == null && comparatorClassName != null) {
try {
final ClassLoaderService classLoaderService = getMetadata().getMetadataBuildingOptions().getServiceRegistry().getService(ClassLoaderService.class);
setComparator((Comparator) classLoaderService.classForName(comparatorClassName).newInstance());
} catch (Exception e) {
throw new MappingException("Could not instantiate comparator class [" + comparatorClassName + "] for collection " + getRole());
}
}
return comparator;
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class ForeignKey method alignColumns.
private void alignColumns(Table referencedTable) {
final int referencedPkColumnSpan = referencedTable.getPrimaryKey().getColumnSpan();
if (referencedPkColumnSpan != getColumnSpan()) {
StringBuilder sb = new StringBuilder();
sb.append("Foreign key (").append(getName()).append(":").append(getTable().getName()).append(" [");
appendColumns(sb, getColumnIterator());
sb.append("])").append(") must have same number of columns as the referenced primary key (").append(referencedTable.getName()).append(" [");
appendColumns(sb, referencedTable.getPrimaryKey().getColumnIterator());
sb.append("])");
throw new MappingException(sb.toString());
}
Iterator fkCols = getColumnIterator();
Iterator pkCols = referencedTable.getPrimaryKey().getColumnIterator();
while (pkCols.hasNext()) {
((Column) fkCols.next()).setLength(((Column) pkCols.next()).getLength());
}
}
Aggregations