Search in sources :

Example 86 with Serializable

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;
}
Also used : EventSource(org.hibernate.event.spi.EventSource) EntityEntry(org.hibernate.engine.spi.EntityEntry) Serializable(java.io.Serializable) AssertionFailure(org.hibernate.AssertionFailure)

Example 87 with Serializable

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;
}
Also used : Serializable(java.io.Serializable)

Example 88 with Serializable

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);
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) EventSource(org.hibernate.event.spi.EventSource) Serializable(java.io.Serializable)

Example 89 with Serializable

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
}
Also used : PersistentCollection(org.hibernate.collection.spi.PersistentCollection) Serializable(java.io.Serializable) PersistenceContext(org.hibernate.engine.spi.PersistenceContext)

Example 90 with Serializable

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);
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) Serializable(java.io.Serializable)

Aggregations

Serializable (java.io.Serializable)1280 Test (org.junit.Test)334 HashMap (java.util.HashMap)265 ArrayList (java.util.ArrayList)215 Map (java.util.Map)127 List (java.util.List)94 Metacard (ddf.catalog.data.Metacard)89 IOException (java.io.IOException)89 HashSet (java.util.HashSet)70 Session (org.hibernate.Session)63 Task (org.apache.hadoop.hive.ql.exec.Task)57 ByteArrayInputStream (java.io.ByteArrayInputStream)50 Set (java.util.Set)50 ObjectInputStream (java.io.ObjectInputStream)43 Date (java.util.Date)41 LinkedHashMap (java.util.LinkedHashMap)40 EntityPersister (org.hibernate.persister.entity.EntityPersister)34 File (java.io.File)33 Iterator (java.util.Iterator)33 URI (java.net.URI)32