Example usage for org.hibernate LazyInitializationException LazyInitializationException

List of usage examples for org.hibernate LazyInitializationException LazyInitializationException

Introduction

In this page you can find the example usage for org.hibernate LazyInitializationException LazyInitializationException.

Prototype

public LazyInitializationException(String message) 

Source Link

Document

Constructs a LazyInitializationException using the given message.

Usage

From source file:org.babyfish.hibernate.collection.type.AbstractMACollectionType.java

License:Open Source License

protected static void throwLazyInitializationException(AbstractPersistentCollection c, String message) {
    throw new LazyInitializationException("failed to lazily initialize a collection"
            + (c.getRole() == null ? "" : " of role: " + c.getRole()) + ", " + message);
}

From source file:org.babyfish.hibernate.model.loader.HibernateObjectModelScalarLoader.java

License:Open Source License

@Override
public final void loadScalars(Collection<ObjectModel> objectModels, int[] scalarPropertyIds) {

    SessionImplementor session = this.session;
    if (session == null) {
        throw new LazyInitializationException("entity with lazy properties is not associated with a session");
    } else if (!session.isOpen() || !session.isConnected()) {
        throw new LazyInitializationException("session is not connected");
    }//from  w  w w.j  a  v  a 2 s. c  o m

    int partitionSize = -1;
    Dialect dialect = session.getFactory().getDialect();
    if (dialect instanceof LimitedListDialect) {
        int maxListLength = ((LimitedListDialect) dialect).getMaxListLength();
        if (objectModels.size() > maxListLength) {
            partitionSize = maxListLength;
        }
    }

    if (partitionSize == -1) {
        this.loadScalarsImpl(objectModels, scalarPropertyIds);
        return;
    }

    List<ObjectModel> objectModelList;
    if (objectModels instanceof List<?>) {
        objectModelList = (List<ObjectModel>) objectModels;
    } else {
        objectModelList = new ArrayList<>(objectModels);
    }
    while (!objectModelList.isEmpty()) {
        if (objectModelList.size() <= partitionSize) {
            this.loadScalarsImpl(objectModelList, scalarPropertyIds);
            break;
        }
        this.loadScalarsImpl(objectModelList.subList(0, partitionSize), scalarPropertyIds);
        objectModelList = objectModelList.subList(partitionSize, objectModelList.size());
    }
}