Author: adamw
Date: 2009-11-23 10:51:56 -0500 (Mon, 23 Nov 2009)
New Revision: 18025
Added:
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/serialization/
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/serialization/SerializingCollection.java
Removed:
core/branches/envers-hibernate-3.3/src/main/java/org/jboss/envers/
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/serialization/SerializingCollection.java
Modified:
core/branches/envers-hibernate-3.3/pom.xml
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/AnnotationsMetadataReader.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/CollectionProxy.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/ListProxy.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/SetProxy.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/SortedSetProxy.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/AuditException.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/NotAuditedException.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/RevisionDoesNotExistException.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/reader/AuditReaderImplementor.java
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefEdEntity.java
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefIngEntity.java
core/branches/envers-hibernate-3.3/src/test/resources/testng.xml
Log:
svn merge -r 17587:18024
https://svn.jboss.org/repos/hibernate/core/trunk/envers .
Modified: core/branches/envers-hibernate-3.3/pom.xml
===================================================================
--- core/branches/envers-hibernate-3.3/pom.xml 2009-11-23 15:43:31 UTC (rev 18024)
+++ core/branches/envers-hibernate-3.3/pom.xml 2009-11-23 15:51:56 UTC (rev 18025)
@@ -7,7 +7,7 @@
<parent>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-parent</artifactId>
- <version>3.5.0.Beta-1</version>
+ <version>3.5.0-SNAPSHOT</version>
</parent>
<groupId>org.jboss.envers</groupId>
@@ -16,7 +16,7 @@
<name>Envers</name>
<description>Support for entity auditing</description>
- <version>1.2.1-hibernate-3.3</version>
+ <version>1.2.1-hibernate-3.3-SNAPSHOT</version>
<build>
<plugins>
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-11-23
15:43:31 UTC (rev 18024)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-11-23
15:51:56 UTC (rev 18025)
@@ -305,7 +305,14 @@
// Getting the property mapper of the parent - when mapping properties, they need
to be included
String parentEntityName = pc.getSuperclass().getEntityName();
- ExtendedPropertyMapper parentPropertyMapper =
entitiesConfigurations.get(parentEntityName).getPropertyMapper();
+
+ EntityConfiguration parentConfiguration =
entitiesConfigurations.get(parentEntityName);
+ if (parentConfiguration == null) {
+ throw new MappingException("Entity '" + pc.getEntityName() +
"' is audited, but its superclass: '" +
+ parentEntityName + "' is not.");
+ }
+
+ ExtendedPropertyMapper parentPropertyMapper =
parentConfiguration.getPropertyMapper();
ExtendedPropertyMapper propertyMapper = new SubclassPropertyMapper(new
MultiPropertyMapper(), parentPropertyMapper);
return Triple.make(class_mapping, propertyMapper, parentEntityName);
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/AnnotationsMetadataReader.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/AnnotationsMetadataReader.java 2009-11-23
15:43:31 UTC (rev 18024)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/AnnotationsMetadataReader.java 2009-11-23
15:51:56 UTC (rev 18025)
@@ -36,7 +36,6 @@
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
-import org.jboss.envers.*;
/**
* A helper class to read versioning meta-data from annotations on a persistent class.
@@ -69,12 +68,7 @@
if (defaultAudited != null) {
return defaultAudited.modStore();
} else {
- Versioned defaultVersioned = clazz.getAnnotation(Versioned.class);
- if (defaultVersioned != null) {
- return ModificationStore.FULL;
- } else {
- return null;
- }
+ return null;
}
}
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java 2009-11-23
15:43:31 UTC (rev 18024)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java 2009-11-23
15:51:56 UTC (rev 18025)
@@ -26,7 +26,6 @@
import org.hibernate.mapping.Property;
import org.hibernate.mapping.Value;
import org.hibernate.MappingException;
-import org.jboss.envers.Versioned;
/**
* Reads persistent properties form a
@@ -157,12 +156,9 @@
// Checking if this property is explicitly audited or if all properties are.
Audited aud = property.getAnnotation(Audited.class);
- Versioned ver = property.getAnnotation(Versioned.class);
if (aud != null) {
propertyData.setStore(aud.modStore());
propertyData.setRelationTargetAuditMode(aud.targetAuditMode());
- } else if (ver != null) {
- propertyData.setStore(ModificationStore.FULL);
} else {
if (defaultStore != null) {
propertyData.setStore(defaultStore);
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/CollectionProxy.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/CollectionProxy.java 2009-11-23
15:43:31 UTC (rev 18024)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/CollectionProxy.java 2009-11-23
15:51:56 UTC (rev 18025)
@@ -23,6 +23,7 @@
*/
package org.hibernate.envers.entities.mapper.relation.lazy.proxy;
+import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
@@ -31,8 +32,10 @@
/**
* @author Adam Warski (adam at warski dot org)
*/
-public abstract class CollectionProxy<U, T extends Collection<U>> implements
Collection<U> {
- private
org.hibernate.envers.entities.mapper.relation.lazy.initializor.Initializor<T>
initializor;
+public abstract class CollectionProxy<U, T extends Collection<U>> implements
Collection<U>, Serializable {
+ private static final long serialVersionUID = 8698249863871832402L;
+
+ private transient
org.hibernate.envers.entities.mapper.relation.lazy.initializor.Initializor<T>
initializor;
protected T delegate;
protected CollectionProxy() {
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/ListProxy.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/ListProxy.java 2009-11-23
15:43:31 UTC (rev 18024)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/ListProxy.java 2009-11-23
15:51:56 UTC (rev 18025)
@@ -33,7 +33,7 @@
/**
* @author Adam Warski (adam at warski dot org)
*/
-public class ListProxy<U> extends CollectionProxy<U, List<U>>
implements List<U>, Serializable {
+public class ListProxy<U> extends CollectionProxy<U, List<U>>
implements List<U> {
private static final long serialVersionUID = -5479232938279790987L;
public ListProxy() {
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/SetProxy.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/SetProxy.java 2009-11-23
15:43:31 UTC (rev 18024)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/SetProxy.java 2009-11-23
15:51:56 UTC (rev 18025)
@@ -29,7 +29,7 @@
/**
* @author Adam Warski (adam at warski dot org)
*/
-public class SetProxy<U> extends CollectionProxy<U, Set<U>> implements
Set<U>, Serializable {
+public class SetProxy<U> extends CollectionProxy<U, Set<U>> implements
Set<U> {
private static final long serialVersionUID = 131464133074137701L;
public SetProxy() {
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/SortedSetProxy.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/SortedSetProxy.java 2009-11-23
15:43:31 UTC (rev 18024)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/SortedSetProxy.java 2009-11-23
15:51:56 UTC (rev 18025)
@@ -25,12 +25,11 @@
import java.util.Comparator;
import java.util.SortedSet;
-import java.io.Serializable;
/**
* @author Adam Warski (adam at warski dot org)
*/
-public class SortedSetProxy<U> extends CollectionProxy<U, SortedSet<U>>
implements SortedSet<U>, Serializable {
+public class SortedSetProxy<U> extends CollectionProxy<U, SortedSet<U>>
implements SortedSet<U> {
private static final long serialVersionUID = 2092884107178125905L;
public SortedSetProxy() {
@@ -69,4 +68,4 @@
checkInit();
return delegate.last();
}
-}
\ No newline at end of file
+}
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/AuditException.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/AuditException.java 2009-11-23
15:43:31 UTC (rev 18024)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/AuditException.java 2009-11-23
15:51:56 UTC (rev 18025)
@@ -23,13 +23,15 @@
*/
package org.hibernate.envers.exception;
-import org.jboss.envers.exception.VersionsException;
+import org.hibernate.HibernateException;
/**
* @author Adam Warski (adam at warski dot org)
*/
-public class AuditException extends VersionsException {
- public AuditException(String message) {
+public class AuditException extends HibernateException {
+ private static final long serialVersionUID = 4306480965630972168L;
+
+ public AuditException(String message) {
super(message);
}
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/NotAuditedException.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/NotAuditedException.java 2009-11-23
15:43:31 UTC (rev 18024)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/NotAuditedException.java 2009-11-23
15:51:56 UTC (rev 18025)
@@ -23,13 +23,20 @@
*/
package org.hibernate.envers.exception;
-import org.jboss.envers.exception.NotVersionedException;
-
/**
* @author Adam Warski (adam at warski dot org)
*/
-public class NotAuditedException extends NotVersionedException {
- public NotAuditedException(String entityName, String message) {
- super(entityName, message);
+public class NotAuditedException extends AuditException {
+ private static final long serialVersionUID = 4809674577449455510L;
+
+ private final String entityName;
+
+ public NotAuditedException(String entityName, String message) {
+ super(message);
+ this.entityName = entityName;
}
+
+ public String getEntityName() {
+ return entityName;
+ }
}
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/RevisionDoesNotExistException.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/RevisionDoesNotExistException.java 2009-11-23
15:43:31 UTC (rev 18024)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/RevisionDoesNotExistException.java 2009-11-23
15:51:56 UTC (rev 18025)
@@ -28,12 +28,27 @@
/**
* @author Adam Warski (adam at warski dot org)
*/
-public class RevisionDoesNotExistException extends
org.jboss.envers.exception.RevisionDoesNotExistException {
- public RevisionDoesNotExistException(Number revision) {
- super(revision);
+public class RevisionDoesNotExistException extends AuditException {
+ private static final long serialVersionUID = -6417768274074962282L;
+
+ private Number revision;
+ private Date date;
+
+ public RevisionDoesNotExistException(Number revision) {
+ super("Revision " + revision + " does not exist.");
+ this.revision = revision;
}
public RevisionDoesNotExistException(Date date) {
- super(date);
+ super("There is no revision before or at " + date + ".");
+ this.date = date;
}
+
+ public Number getRevision() {
+ return revision;
+ }
+
+ public Date getDate() {
+ return date;
+ }
}
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java 2009-11-23
15:43:31 UTC (rev 18024)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java 2009-11-23
15:51:56 UTC (rev 18025)
@@ -32,6 +32,7 @@
import org.hibernate.envers.exception.RevisionDoesNotExistException;
import org.hibernate.envers.exception.AuditException;
import org.hibernate.envers.query.AuditEntity;
+import org.hibernate.envers.query.AuditQueryCreator;
import static org.hibernate.envers.tools.ArgumentsTools.checkNotNull;
import static org.hibernate.envers.tools.ArgumentsTools.checkPositive;
import org.hibernate.envers.synchronization.AuditSync;
@@ -41,7 +42,6 @@
import org.hibernate.Session;
import org.hibernate.event.EventSource;
import org.hibernate.engine.SessionImplementor;
-import org.jboss.envers.query.VersionsQueryCreator;
/**
* @author Adam Warski (adam at warski dot org)
@@ -205,7 +205,7 @@
return (T) auditSync.getCurrentRevisionData(session, persist);
}
- public VersionsQueryCreator createQuery() {
- return new VersionsQueryCreator(verCfg, this);
+ public AuditQueryCreator createQuery() {
+ return new AuditQueryCreator(verCfg, this);
}
}
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/reader/AuditReaderImplementor.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/reader/AuditReaderImplementor.java 2009-11-23
15:43:31 UTC (rev 18024)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/reader/AuditReaderImplementor.java 2009-11-23
15:51:56 UTC (rev 18025)
@@ -27,13 +27,12 @@
import org.hibernate.Session;
import org.hibernate.engine.SessionImplementor;
-import org.jboss.envers.VersionsReader;
/**
* An interface exposed by a VersionsReader to library-facing classes.
* @author Adam Warski (adam at warski dot org)
*/
-public interface AuditReaderImplementor extends AuditReader, VersionsReader {
+public interface AuditReaderImplementor extends AuditReader {
SessionImplementor getSessionImplementor();
Session getSession();
FirstLevelCache getFirstLevelCache();
Modified:
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefEdEntity.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefEdEntity.java 2009-11-23
15:43:31 UTC (rev 18024)
+++
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefEdEntity.java 2009-11-23
15:51:56 UTC (rev 18025)
@@ -24,6 +24,7 @@
package org.hibernate.envers.test.entities.onetomany;
import java.util.Collection;
+import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
@@ -35,7 +36,9 @@
* @author Adam Warski (adam at warski dot org)
*/
@Entity
-public class CollectionRefEdEntity {
+public class CollectionRefEdEntity implements Serializable {
+ private static final long serialVersionUID = -1694020123633796683L;
+
@Id
private Integer id;
@@ -46,7 +49,7 @@
@OneToMany(mappedBy="reference")
private Collection<CollectionRefIngEntity> reffering;
- public CollectionRefEdEntity() {
+ public CollectionRefEdEntity() {
}
public CollectionRefEdEntity(Integer id, String data) {
Modified:
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefIngEntity.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefIngEntity.java 2009-11-23
15:43:31 UTC (rev 18024)
+++
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefIngEntity.java 2009-11-23
15:51:56 UTC (rev 18025)
@@ -29,12 +29,16 @@
import org.hibernate.envers.Audited;
+import java.io.Serializable;
+
/**
* ReferencIng entity
* @author Adam Warski (adam at warski dot org)
*/
@Entity
-public class CollectionRefIngEntity {
+public class CollectionRefIngEntity implements Serializable {
+ private static final long serialVersionUID = -9019967223928425707L;
+
@Id
private Integer id;
@@ -45,7 +49,7 @@
@ManyToOne
private CollectionRefEdEntity reference;
- public CollectionRefIngEntity() { }
+ public CollectionRefIngEntity() { }
public CollectionRefIngEntity(Integer id, String data, CollectionRefEdEntity
reference) {
this.id = id;
Copied:
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/serialization
(from rev 18024,
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/serialization)
Deleted:
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/serialization/SerializingCollection.java
===================================================================
---
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/serialization/SerializingCollection.java 2009-11-23
15:43:31 UTC (rev 18024)
+++
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/serialization/SerializingCollection.java 2009-11-23
15:51:56 UTC (rev 18025)
@@ -1,110 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.envers.test.integration.serialization;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ObjectInputStream;
-import java.io.IOException;
-import javax.persistence.EntityManager;
-
-import org.hibernate.envers.test.AbstractEntityTest;
-import org.hibernate.envers.test.entities.onetomany.CollectionRefEdEntity;
-import org.hibernate.envers.test.entities.onetomany.CollectionRefIngEntity;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import org.hibernate.ejb.Ejb3Configuration;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class SerializingCollection extends AbstractEntityTest {
- private Integer ed1_id;
- private Integer ing1_id;
-
- public void configure(Ejb3Configuration cfg) {
- cfg.addAnnotatedClass(CollectionRefEdEntity.class);
- cfg.addAnnotatedClass(CollectionRefIngEntity.class);
- }
-
- @BeforeClass(dependsOnMethods = "init")
- public void initData() {
- EntityManager em = getEntityManager();
-
- CollectionRefEdEntity ed1 = new CollectionRefEdEntity(1, "data_ed_1");
-
- CollectionRefIngEntity ing1 = new CollectionRefIngEntity(3,
"data_ing_1", ed1);
-
- // Revision 1
- em.getTransaction().begin();
-
- em.persist(ed1);
- em.persist(ing1);
-
- em.getTransaction().commit();
-
- //
-
- ed1_id = ed1.getId();
- ing1_id = ing1.getId();
- }
-
- @Test
- public void testDetach()throws Exception {
- CollectionRefIngEntity ing1 =
getEntityManager().find(CollectionRefIngEntity.class, ing1_id);
- CollectionRefEdEntity rev1 = getAuditReader().find(CollectionRefEdEntity.class,
ed1_id, 1);
-
- // First forcing loading of the collection
- assert rev1.getReffering().size() == 1;
-
- // Now serializing and de-serializing the
- rev1 = serializeDeserialize(rev1);
-
- // And checking the colleciton again
- assert rev1.getReffering().contains(ing1);
- assert rev1.getReffering().size() == 1;
-
- }
-
- @SuppressWarnings({"unchecked"})
- public static <T> T serializeDeserialize(T o) throws Exception {
- if (o == null) return null;
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(o);
- byte[] buffer = baos.toByteArray();
- baos.close();
-
- ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
- ObjectInputStream ois = new ObjectInputStream(bais);
- return (T) ois.readObject();
- }
-}
Copied:
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/serialization/SerializingCollection.java
(from rev 18024,
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/serialization/SerializingCollection.java)
===================================================================
---
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/serialization/SerializingCollection.java
(rev 0)
+++
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/serialization/SerializingCollection.java 2009-11-23
15:51:56 UTC (rev 18025)
@@ -0,0 +1,110 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.envers.test.integration.serialization;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ObjectInputStream;
+import java.io.IOException;
+import javax.persistence.EntityManager;
+
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.entities.onetomany.CollectionRefEdEntity;
+import org.hibernate.envers.test.entities.onetomany.CollectionRefIngEntity;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.ejb.Ejb3Configuration;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class SerializingCollection extends AbstractEntityTest {
+ private Integer ed1_id;
+ private Integer ing1_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(CollectionRefEdEntity.class);
+ cfg.addAnnotatedClass(CollectionRefIngEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ CollectionRefEdEntity ed1 = new CollectionRefEdEntity(1, "data_ed_1");
+
+ CollectionRefIngEntity ing1 = new CollectionRefIngEntity(3,
"data_ing_1", ed1);
+
+ // Revision 1
+ em.getTransaction().begin();
+
+ em.persist(ed1);
+ em.persist(ing1);
+
+ em.getTransaction().commit();
+
+ //
+
+ ed1_id = ed1.getId();
+ ing1_id = ing1.getId();
+ }
+
+ @Test
+ public void testDetach()throws Exception {
+ CollectionRefIngEntity ing1 =
getEntityManager().find(CollectionRefIngEntity.class, ing1_id);
+ CollectionRefEdEntity rev1 = getAuditReader().find(CollectionRefEdEntity.class,
ed1_id, 1);
+
+ // First forcing loading of the collection
+ assert rev1.getReffering().size() == 1;
+
+ // Now serializing and de-serializing the
+ rev1 = serializeDeserialize(rev1);
+
+ // And checking the colleciton again
+ assert rev1.getReffering().contains(ing1);
+ assert rev1.getReffering().size() == 1;
+
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public static <T> T serializeDeserialize(T o) throws Exception {
+ if (o == null) return null;
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(o);
+ byte[] buffer = baos.toByteArray();
+ baos.close();
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ return (T) ois.readObject();
+ }
+}
Modified: core/branches/envers-hibernate-3.3/src/test/resources/testng.xml
===================================================================
--- core/branches/envers-hibernate-3.3/src/test/resources/testng.xml 2009-11-23 15:43:31
UTC (rev 18024)
+++ core/branches/envers-hibernate-3.3/src/test/resources/testng.xml 2009-11-23 15:51:56
UTC (rev 18025)
@@ -54,6 +54,7 @@
<package name="org.hibernate.envers.test.integration.sameids"
/>
<package name="org.hibernate.envers.test.integration.secondary"
/>
<package
name="org.hibernate.envers.test.integration.secondary.ids" />
+ <package
name="org.hibernate.envers.test.integration.serialization" />
<package name="org.hibernate.envers.test.integration.superclass"
/>
</packages>
</test>