use of org.hibernate.AssertionFailure in project hibernate-orm by hibernate.
the class MapBinder method makeOneToManyMapKeyColumnNullableIfNotInProperty.
private void makeOneToManyMapKeyColumnNullableIfNotInProperty(final XProperty property) {
final org.hibernate.mapping.Map map = (org.hibernate.mapping.Map) this.collection;
if (map.isOneToMany() && property.isAnnotationPresent(MapKeyColumn.class)) {
final Value indexValue = map.getIndex();
if (indexValue.getColumnSpan() != 1) {
throw new AssertionFailure("Map key mapped by @MapKeyColumn does not have 1 column");
}
final Selectable selectable = indexValue.getColumnIterator().next();
if (selectable.isFormula()) {
throw new AssertionFailure("Map key mapped by @MapKeyColumn is a Formula");
}
Column column = (Column) map.getIndex().getColumnIterator().next();
if (!column.isNullable()) {
final PersistentClass persistentClass = ((OneToMany) map.getElement()).getAssociatedClass();
// need to check "un-joined" properties.
if (!propertyIteratorContainsColumn(persistentClass.getUnjoinedPropertyIterator(), column)) {
// The index column is not mapped to an associated entity property so we can
// safely make the index column nullable.
column.setNullable(true);
}
}
}
}
use of org.hibernate.AssertionFailure in project hibernate-orm by hibernate.
the class EnumType method setParameterValues.
@Override
public void setParameterValues(Properties parameters) {
// IMPL NOTE: we handle 2 distinct cases here:
// 1) we are passed a ParameterType instance in the incoming Properties - generally
// speaking this indicates the annotation-binding case, and the passed ParameterType
// represents information about the attribute and annotation
// 2) we are not passed a ParameterType - generally this indicates a hbm.xml binding case.
final ParameterType reader = (ParameterType) parameters.get(PARAMETER_TYPE);
if (reader != null) {
enumClass = reader.getReturnedClass().asSubclass(Enum.class);
final boolean isOrdinal;
final javax.persistence.EnumType enumType = getEnumType(reader);
if (enumType == null) {
isOrdinal = true;
} else if (javax.persistence.EnumType.ORDINAL.equals(enumType)) {
isOrdinal = true;
} else if (javax.persistence.EnumType.STRING.equals(enumType)) {
isOrdinal = false;
} else {
throw new AssertionFailure("Unknown EnumType: " + enumType);
}
final EnumJavaTypeDescriptor enumJavaDescriptor = (EnumJavaTypeDescriptor) typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor(enumClass);
if (isOrdinal) {
this.enumValueConverter = new OrdinalEnumValueConverter(enumJavaDescriptor);
} else {
this.enumValueConverter = new NamedEnumValueConverter(enumJavaDescriptor);
}
} else {
final String enumClassName = (String) parameters.get(ENUM);
try {
enumClass = ReflectHelper.classForName(enumClassName, this.getClass()).asSubclass(Enum.class);
} catch (ClassNotFoundException exception) {
throw new HibernateException("Enum class not found: " + enumClassName, exception);
}
this.enumValueConverter = interpretParameters(parameters);
}
LOG.debugf("Using %s-based conversion for Enum %s", isOrdinal() ? "ORDINAL" : "NAMED", enumClass.getName());
}
use of org.hibernate.AssertionFailure in project hibernate-orm by hibernate.
the class StandardCacheEntryImpl method assemble.
/**
* Assemble the previously disassembled state represented by this entry into the given entity instance.
*
* Additionally manages the PreLoadEvent callbacks.
*
* @param instance The entity instance
* @param id The entity identifier
* @param persister The entity persister
* @param interceptor (currently unused)
* @param session The session
*
* @return The assembled state
*
* @throws HibernateException Indicates a problem performing assembly or calling the PreLoadEventListeners.
*
* @see org.hibernate.type.Type#assemble
* @see org.hibernate.type.Type#disassemble
*/
public Object[] assemble(final Object instance, final Serializable id, final EntityPersister persister, final Interceptor interceptor, final EventSource session) throws HibernateException {
if (!persister.getEntityName().equals(subclass)) {
throw new AssertionFailure("Tried to assemble a different subclass instance");
}
// assembled state gets put in a new array (we read from cache by value!)
final Object[] state = TypeHelper.assemble(disassembledState, persister.getPropertyTypes(), session, instance);
// persister.setIdentifier(instance, id); //before calling interceptor, for consistency with normal load
// TODO: reuse the PreLoadEvent
final PreLoadEvent preLoadEvent = new PreLoadEvent(session).setEntity(instance).setState(state).setId(id).setPersister(persister);
final EventListenerGroup<PreLoadEventListener> listenerGroup = session.getFactory().getServiceRegistry().getService(EventListenerRegistry.class).getEventListenerGroup(EventType.PRE_LOAD);
for (PreLoadEventListener listener : listenerGroup.listeners()) {
listener.onPreLoad(preLoadEvent);
}
persister.setPropertyValues(instance, state);
return state;
}
use of org.hibernate.AssertionFailure in project hibernate-orm by hibernate.
the class StatefulPersistenceContext method addCollection.
/**
* Add a collection to the cache, with a given collection entry.
*
* @param coll The collection for which we are adding an entry.
* @param entry The entry representing the collection.
* @param key The key of the collection's entry.
*/
private void addCollection(PersistentCollection coll, CollectionEntry entry, Serializable key) {
collectionEntries.put(coll, entry);
final CollectionKey collectionKey = new CollectionKey(entry.getLoadedPersister(), key);
final PersistentCollection old = collectionsByKey.put(collectionKey, coll);
if (old != null) {
if (old == coll) {
throw new AssertionFailure("bug adding collection twice");
}
// or should it actually throw an exception?
old.unsetSession(session);
collectionEntries.remove(old);
// watch out for a case where old is still referenced
// somewhere in the object graph! (which is a user error)
}
}
use of org.hibernate.AssertionFailure in project hibernate-orm by hibernate.
the class TwoPhaseLoad method initializeEntity.
/**
* Perform the second step of 2-phase load. Fully initialize the entity
* instance.
* <p/>
* After processing a JDBC result set, we "resolve" all the associations
* between the entities which were instantiated and had their state
* "hydrated" into an array
*
* @param entity The entity being loaded
* @param readOnly Is the entity being loaded as read-only
* @param session The Session
* @param preLoadEvent The (re-used) pre-load event
*/
public static void initializeEntity(final Object entity, final boolean readOnly, final SharedSessionContractImplementor session, final PreLoadEvent preLoadEvent) {
final PersistenceContext persistenceContext = session.getPersistenceContext();
final EntityEntry entityEntry = persistenceContext.getEntry(entity);
if (entityEntry == null) {
throw new AssertionFailure("possible non-threadsafe access to the session");
}
doInitializeEntity(entity, entityEntry, readOnly, session, preLoadEvent);
}
Aggregations