use of java.io.Serializable in project hibernate-orm by hibernate.
the class DefaultSaveOrUpdateEventListener method entityIsTransient.
/**
* The given save-update event named a transient entity.
* <p/>
* Here, we will perform the save processing.
*
* @param event The save event to be handled.
*
* @return The entity's identifier afterQuery saving.
*/
protected Serializable entityIsTransient(SaveOrUpdateEvent event) {
LOG.trace("Saving transient instance");
final EventSource source = event.getSession();
EntityEntry entityEntry = event.getEntry();
if (entityEntry != null) {
if (entityEntry.getStatus() == Status.DELETED) {
source.forceFlush(entityEntry);
} else {
throw new AssertionFailure("entity was persistent");
}
}
Serializable id = saveWithGeneratedOrRequestedId(event);
source.getPersistenceContext().reassociateProxy(event.getObject(), id);
return id;
}
use of java.io.Serializable in project hibernate-orm by hibernate.
the class CompositeNestedGeneratedValueGenerator method generate.
@Override
public Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException {
final Serializable context = generationContextLocator.locateGenerationContext(session, object);
for (Object generationPlan : generationPlans) {
final GenerationPlan plan = (GenerationPlan) generationPlan;
plan.execute(session, object, context);
}
return context;
}
use of java.io.Serializable in project hibernate-orm by hibernate.
the class JpaDeleteEventListener method performDetachedEntityDeletionCheck.
@Override
protected void performDetachedEntityDeletionCheck(DeleteEvent event) {
EventSource source = event.getSession();
String entityName = event.getEntityName();
EntityPersister persister = source.getEntityPersister(entityName, event.getObject());
Serializable id = persister.getIdentifier(event.getObject(), source);
entityName = entityName == null ? source.guessEntityName(event.getObject()) : entityName;
throw new IllegalArgumentException("Removing a detached instance " + entityName + "#" + id);
}
use of java.io.Serializable in project hibernate-orm by hibernate.
the class Loader method readCollectionElement.
/**
* Read one collection element from the current row of the JDBC result set
*/
private void readCollectionElement(final Object optionalOwner, final Serializable optionalKey, final CollectionPersister persister, final CollectionAliases descriptor, final ResultSet rs, final SharedSessionContractImplementor session) throws HibernateException, SQLException {
final PersistenceContext persistenceContext = session.getPersistenceContext();
final Serializable collectionRowKey = (Serializable) persister.readKey(rs, descriptor.getSuffixedKeyAliases(), session);
if (collectionRowKey != null) {
if (LOG.isDebugEnabled()) {
LOG.debugf("Found row of collection: %s", MessageHelper.collectionInfoString(persister, collectionRowKey, getFactory()));
}
Object owner = optionalOwner;
if (owner == null) {
owner = persistenceContext.getCollectionOwner(collectionRowKey, persister);
if (owner == null) {
//TODO: This is assertion is disabled because there is a bug that means the
// original owner of a transient, uninitialized collection is not known
// if the collection is re-referenced by a different object associated
// with the current Session
//throw new AssertionFailure("bug loading unowned collection");
}
}
PersistentCollection rowCollection = persistenceContext.getLoadContexts().getCollectionLoadContext(rs).getLoadingCollection(persister, collectionRowKey);
if (rowCollection != null) {
rowCollection.readFrom(rs, persister, descriptor, owner);
}
} else if (optionalKey != null) {
if (LOG.isDebugEnabled()) {
LOG.debugf("Result set contains (possibly empty) collection: %s", MessageHelper.collectionInfoString(persister, optionalKey, getFactory()));
}
persistenceContext.getLoadContexts().getCollectionLoadContext(rs).getLoadingCollection(persister, // handle empty collection
optionalKey);
}
// else no collection element, but also no owner
}
use of java.io.Serializable in project hibernate-orm by hibernate.
the class StatelessSessionImpl method delete.
@Override
public void delete(String entityName, Object entity) {
checkOpen();
EntityPersister persister = getEntityPersister(entityName, entity);
Serializable id = persister.getIdentifier(entity, this);
Object version = persister.getVersion(entity);
persister.delete(id, version, entity, this);
}
Aggregations