diff --git a/hibernate-core/src/main/java/org/hibernate/Hibernate.java b/hibernate-core/src/main/java/org/hibernate/Hibernate.java
index 9f4fea0184d5..5d6ad5e0845b 100644
--- a/hibernate-core/src/main/java/org/hibernate/Hibernate.java
+++ b/hibernate-core/src/main/java/org/hibernate/Hibernate.java
@@ -20,6 +20,7 @@
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
+import org.hibernate.collection.spi.LazyInitializable;
/**
*
@@ -61,8 +62,8 @@ public static void initialize(Object proxy) throws HibernateException {
if ( proxy instanceof HibernateProxy ) {
( (HibernateProxy) proxy ).getHibernateLazyInitializer().initialize();
}
- else if ( proxy instanceof PersistentCollection ) {
- ( (PersistentCollection) proxy ).forceInitialization();
+ else if ( proxy instanceof LazyInitializable ) {
+ ( (LazyInitializable) proxy ).forceInitialization();
}
else if ( proxy instanceof PersistentAttributeInterceptable ) {
final PersistentAttributeInterceptable interceptable = (PersistentAttributeInterceptable) proxy;
@@ -91,8 +92,8 @@ else if ( proxy instanceof PersistentAttributeInterceptable ) {
}
return true;
}
- else if ( proxy instanceof PersistentCollection ) {
- return ( (PersistentCollection) proxy ).wasInitialized();
+ else if ( proxy instanceof LazyInitializable ) {
+ return ( (LazyInitializable) proxy ).wasInitialized();
}
else {
return true;
diff --git a/hibernate-core/src/main/java/org/hibernate/collection/spi/LazyInitializable.java b/hibernate-core/src/main/java/org/hibernate/collection/spi/LazyInitializable.java
new file mode 100644
index 000000000000..38c8345181ec
--- /dev/null
+++ b/hibernate-core/src/main/java/org/hibernate/collection/spi/LazyInitializable.java
@@ -0,0 +1,33 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
+ * See the lgpl.txt file in the root directory or .
+ */
+package org.hibernate.collection.spi;
+
+import org.hibernate.Incubating;
+
+/**
+ * Hibernate "wraps" a java collection in an instance of PersistentCollection. Envers uses custom collection
+ * wrappers (ListProxy, SetProxy, etc). All of them need to extend LazyInitializable, so the
+ * Hibernate.isInitialized method can check if the collection is initialized or not.
+ *
+ * @author Fabricio Gregorio
+ */
+@Incubating
+public interface LazyInitializable {
+
+ /**
+ * Is this instance initialized?
+ *
+ * @return Was this collection initialized? Or is its data still not (fully) loaded?
+ */
+ boolean wasInitialized();
+
+ /**
+ * To be called internally by the session, forcing immediate initialization.
+ */
+ void forceInitialization();
+
+}
diff --git a/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentCollection.java b/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentCollection.java
index 0a98641c38b7..8fa8817d0d60 100644
--- a/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentCollection.java
+++ b/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentCollection.java
@@ -45,7 +45,7 @@
*
* @author Gavin King
*/
-public interface PersistentCollection {
+public interface PersistentCollection extends LazyInitializable {
/**
* Get the owning entity. Note that the owner is only
* set during the flush cycle, and when a new collection
@@ -271,11 +271,6 @@ Object readFrom(ResultSet rs, CollectionPersister role, CollectionAliases descri
*/
Serializable getSnapshot(CollectionPersister persister);
- /**
- * To be called internally by the session, forcing immediate initialization.
- */
- void forceInitialization();
-
/**
* Does the given element/entry exist in the collection?
*
@@ -335,13 +330,6 @@ Object readFrom(ResultSet rs, CollectionPersister role, CollectionAliases descri
*/
boolean isWrapper(Object collection);
- /**
- * Is this instance initialized?
- *
- * @return Was this collection initialized? Or is its data still not (fully) loaded?
- */
- boolean wasInitialized();
-
/**
* Does this instance have any "queued" operations?
*
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/CollectionProxy.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/CollectionProxy.java
index 3e96d93f797c..fe4d04532c52 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/CollectionProxy.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/CollectionProxy.java
@@ -9,13 +9,15 @@
import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
+import org.hibernate.collection.spi.LazyInitializable;
import org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor;
/**
* @author Adam Warski (adam at warski dot org)
*/
-public abstract class CollectionProxy> implements Collection, Serializable {
+public abstract class CollectionProxy> implements Collection, LazyInitializable, Serializable {
+
private static final long serialVersionUID = 8698249863871832402L;
private transient org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor initializor;
@@ -34,6 +36,16 @@ protected void checkInit() {
}
}
+ @Override
+ public final boolean wasInitialized() {
+ return delegate != null;
+ }
+
+ @Override
+ public final void forceInitialization() {
+ checkInit();
+ }
+
@Override
public int size() {
checkInit();
@@ -118,7 +130,7 @@ public String toString() {
return delegate.toString();
}
- @SuppressWarnings({"EqualsWhichDoesntCheckParameterClass"})
+ @SuppressWarnings({ "EqualsWhichDoesntCheckParameterClass" })
@Override
public boolean equals(Object obj) {
checkInit();
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/MapProxy.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/MapProxy.java
index 6ee143ea00f2..1aeb142055be 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/MapProxy.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/lazy/proxy/MapProxy.java
@@ -10,13 +10,14 @@
import java.util.Collection;
import java.util.Map;
import java.util.Set;
-
+import org.hibernate.collection.spi.LazyInitializable;
import org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor;
/**
* @author Adam Warski (adam at warski dot org)
*/
-public class MapProxy implements Map, Serializable {
+public class MapProxy implements Map, LazyInitializable, Serializable {
+
private static final long serialVersionUID = 8418037541773074646L;
private transient Initializor