Title: [1974] trunk: Add support for Hibernate 4 (XSTR-699).

Diff

Modified: trunk/pom.xml (1973 => 1974)


--- trunk/pom.xml	2012-04-16 20:45:04 UTC (rev 1973)
+++ trunk/pom.xml	2012-06-08 21:16:01 UTC (rev 1974)
@@ -1,7 +1,7 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     <!--
      Copyright (C) 2006 Joe Walnes.
-     Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 XStream committers.
+     Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 XStream committers.
      All rights reserved.
      
      The software in this package is published under the terms of the BSD
@@ -29,9 +29,18 @@
     <url>http://xstream.codehaus.org</url>
   </organization>
 
-  <!-- xstream-builder is currently JDK 5 only -->
   <profiles>
     <profile>
+      <id>jdk15-le</id>
+      <activation>
+        <jdk>[,1.5]</jdk>
+      </activation>
+      <properties>
+        <version.hsqldb>1.8.0.10</version.hsqldb>
+        <version.org.hibernate.core>3.3.2.GA</version.org.hibernate.core>
+      </properties>
+    </profile>
+    <profile>
       <id>jdk15-ge</id>
       <activation>
         <jdk>[1.5,)</jdk>
@@ -52,6 +61,7 @@
       </properties>
     </profile>
   </profiles>
+
   <modules>
     <module>xstream</module>
     <module>xstream-hibernate</module>
@@ -232,7 +242,7 @@
         <version>${version.org.hibernate.core}</version>
       </dependency>
       <dependency>
-        <groupId>hsqldb</groupId>
+        <groupId>org.hsqldb</groupId>
         <artifactId>hsqldb</artifactId>
         <version>${version.hsqldb}</version>
       </dependency>
@@ -512,7 +522,7 @@
     <version.commons.io>1.4</version.commons.io>
     <version.commons.lang>2.4</version.commons.lang>
     <version.dom4j>1.6.1</version.dom4j>
-    <version.hsqldb>1.8.0.7</version.hsqldb>
+    <version.hsqldb>2.2.8</version.hsqldb>
     <version.javaassist>3.12.1.GA</version.javaassist>
     <version.jmock>1.0.1</version.jmock>
     <version.joda-time>1.6</version.joda-time>
@@ -520,8 +530,7 @@
     <version.net.sf.kxml.kxml2>2.3.0</version.net.sf.kxml.kxml2>
     <version.org.codehaus.jettison>1.2</version.org.codehaus.jettison>
     <version.org.codehaus.woodstox.asl>3.2.7</version.org.codehaus.woodstox.asl>
-    <version.org.hibernate.core>3.3.2.GA</version.org.hibernate.core><!-- last version on central -->
-    <!-- version.org.hibernate.core>3.5.6-Final</version.org.hibernate.core -->
+    <version.org.hibernate.core>4.1.4.Final</version.org.hibernate.core>
     <version.org.jdom>1.1</version.org.jdom>
     <version.org.json>20080701</version.org.json>
     <version.org.slf4j>1.6.1</version.org.slf4j>

Modified: trunk/xstream-distribution/src/content/changes.html (1973 => 1974)


--- trunk/xstream-distribution/src/content/changes.html	2012-04-16 20:45:04 UTC (rev 1973)
+++ trunk/xstream-distribution/src/content/changes.html	2012-06-08 21:16:01 UTC (rev 1974)
@@ -37,6 +37,7 @@
     <ul>
     	<li>Support java.util.concurrent.ConcurrentHashMap with the MapConverter. This will also avoid a bug in JRockit
     	JDK reported in JIRA:XSTR-608.</li>
+    	<li>JIRA:XSTR-699: Support for Hibernate 4 with XStream's Hibernate module as default for Java 6 or higher.</li>
     </ul>
 
     <h2>Minor changes</h2>
@@ -59,6 +60,7 @@
     	JIRA:XSTR-695).</li>
     	<li>FieldDictionary may call sort of FieldKeySorter implementation with wrong type as key.</li>
     	<li>Sometimes DependencyInjectionFactory tries to instantiate objects with mismatching constructor arguments.</li>
+    	<li>HSQLDB has to be a test dependency only for XStream's Hibernate module.</li>
     </ul>
 
     <h1 id="1.4.2">1.4.2</h1>

Modified: trunk/xstream-distribution/src/content/download.html (1973 => 1974)


--- trunk/xstream-distribution/src/content/download.html	2012-04-16 20:45:04 UTC (rev 1973)
+++ trunk/xstream-distribution/src/content/download.html	2012-06-08 21:16:01 UTC (rev 1974)
@@ -49,8 +49,8 @@
     <p>Previous releases of XStream are also available. However, use of the latest stable version is recommended.</p>
 
     <ul>
-       <li><a href="" releases (&gt;= 1.2)</a></li>
-       <li><a href="" releases (&lt;= 1.2)</a></li>
+       <li><a href="" releases (&gt;= 1.2)</a></li>
+       <li><a href="" releases (&lt;= 1.2)</a></li>
     </ul>
 
     <h1 id="optional-deps">Optional Dependencies</h1>
@@ -58,7 +58,7 @@
     <ul>
     	<li>Supported XML parsers and packages:
     	<ul>
-      		<li><a href="" the <a href="" pull parser API</a> and factory to detect available implementations.</li>
+      		<li><a href="" the <a href="" pull parser API</a> and factory to detect available implementations.</li>
       		<li><a href="" an XML pull parser (recommended).</li>
       		<li><a href="" or <a href="" an XML pull parser.</li>
       		<li><a href="" easy XML representation and manipulation framework.</li>
@@ -78,5 +78,16 @@
       	</li>
     </ul>
 
+    <h1 id="hibernate">Dependencies Hibernate Module</h1>
+
+    <ul>
+    	<li>Supported Hibernate versions:
+    	<ul>
+      		<li><a href="" 4.1.4</a>, for Java 6 or higher.</li>
+      		<li><a href="" 3.3.2</a>, up to Java 5.</li>
+      	</ul>
+      	</li>
+    </ul>
+
   </body>
 </html>

Property changes: trunk/xstream-hibernate


Modified: svn:ignore

target + .* target *.classpath

Modified: trunk/xstream-hibernate/pom.xml (1973 => 1974)


--- trunk/xstream-hibernate/pom.xml	2012-04-16 20:45:04 UTC (rev 1973)
+++ trunk/xstream-hibernate/pom.xml	2012-06-08 21:16:01 UTC (rev 1974)
@@ -1,6 +1,6 @@
 <?xml version="1.0"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     <!--
-     Copyright (C) 2011 XStream committers.
+     Copyright (C) 2011, 2012 XStream committers.
      All rights reserved.
      
      The software in this package is published under the terms of the BSD
@@ -21,9 +21,9 @@
 
   <profiles>
     <profile>
-      <id>jdk15-ge</id>
+      <id>jdk16-ge</id>
       <activation>
-        <jdk>[1.5,)</jdk>
+        <jdk>[1.6,)</jdk>
       </activation>
       <build>
         <plugins>
@@ -121,8 +121,9 @@
         <artifactId>hibernate-core</artifactId>
     </dependency>
     <dependency>
-        <groupId>hsqldb</groupId>
+        <groupId>org.hsqldb</groupId>
         <artifactId>hsqldb</artifactId>
+        <scope>test</scope>
     </dependency>
     <dependency>
         <groupId>org.slf4j</groupId>

Modified: trunk/xstream-hibernate/src/java/com/thoughtworks/xstream/hibernate/converter/HibernatePersistentCollectionConverter.java (1973 => 1974)


--- trunk/xstream-hibernate/src/java/com/thoughtworks/xstream/hibernate/converter/HibernatePersistentCollectionConverter.java	2012-04-16 20:45:04 UTC (rev 1973)
+++ trunk/xstream-hibernate/src/java/com/thoughtworks/xstream/hibernate/converter/HibernatePersistentCollectionConverter.java	2012-06-08 21:16:01 UTC (rev 1974)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 XStream Committers.
+ * Copyright (C) 2011, 2012 XStream Committers.
  * All rights reserved.
  *
  * The software in this package is published under the terms of the BSD
@@ -13,18 +13,15 @@
 import com.thoughtworks.xstream.converters.ConversionException;
 import com.thoughtworks.xstream.converters.UnmarshallingContext;
 import com.thoughtworks.xstream.converters.collections.CollectionConverter;
+import com.thoughtworks.xstream.hibernate.util.Hibernate;
 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
 import com.thoughtworks.xstream.mapper.Mapper;
 
-import org.hibernate.collection.PersistentBag;
-import org.hibernate.collection.PersistentList;
-import org.hibernate.collection.PersistentSet;
 
-
 /**
- * A converter for Hibernate's {@link PersistentBag}, {@link PersistentList} and
- * {@link PersistentSet}. The converter will drop any reference to the Hibernate collection and
- * emit at serialization time an equivalent JDK collection instead.
+ * A converter for Hibernate's PersistentBag, PersistentList and PersistentSet. The converter
+ * will drop any reference to the Hibernate collection and emit at serialization time an
+ * equivalent JDK collection instead.
  * 
  * @author J&ouml;rg Schaible
  * @since 1.4
@@ -42,9 +39,9 @@
     }
 
     public boolean canConvert(final Class type) {
-        return type == PersistentBag.class
-            || type == PersistentList.class
-            || type == PersistentSet.class;
+        return type == Hibernate.PersistentBag
+            || type == Hibernate.PersistentList
+            || type == Hibernate.PersistentSet;
     }
 
     public Object unmarshal(final HierarchicalStreamReader reader,

Modified: trunk/xstream-hibernate/src/java/com/thoughtworks/xstream/hibernate/converter/HibernatePersistentMapConverter.java (1973 => 1974)


--- trunk/xstream-hibernate/src/java/com/thoughtworks/xstream/hibernate/converter/HibernatePersistentMapConverter.java	2012-04-16 20:45:04 UTC (rev 1973)
+++ trunk/xstream-hibernate/src/java/com/thoughtworks/xstream/hibernate/converter/HibernatePersistentMapConverter.java	2012-06-08 21:16:01 UTC (rev 1974)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 XStream Committers.
+ * Copyright (C) 2011, 2012 XStream Committers.
  * All rights reserved.
  *
  * The software in this package is published under the terms of the BSD
@@ -13,15 +13,14 @@
 import com.thoughtworks.xstream.converters.ConversionException;
 import com.thoughtworks.xstream.converters.UnmarshallingContext;
 import com.thoughtworks.xstream.converters.collections.MapConverter;
+import com.thoughtworks.xstream.hibernate.util.Hibernate;
 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
 import com.thoughtworks.xstream.mapper.Mapper;
 
-import org.hibernate.collection.PersistentMap;
 
-
 /**
- * A converter for Hibernate's {@link PersistentMap}. The converter will drop any reference to
- * the Hibernate collection and emit at serialization time an equivalent JDK collection instead.
+ * A converter for Hibernate's PersistentMap. The converter will drop any reference to the
+ * Hibernate collection and emit at serialization time an equivalent JDK collection instead.
  * 
  * @author J&ouml;rg Schaible
  * @since 1.4
@@ -39,7 +38,7 @@
     }
 
     public boolean canConvert(final Class type) {
-        return type == PersistentMap.class;
+        return type == Hibernate.PersistentMap;
     }
 
     public Object unmarshal(final HierarchicalStreamReader reader,

Modified: trunk/xstream-hibernate/src/java/com/thoughtworks/xstream/hibernate/converter/HibernatePersistentSortedMapConverter.java (1973 => 1974)


--- trunk/xstream-hibernate/src/java/com/thoughtworks/xstream/hibernate/converter/HibernatePersistentSortedMapConverter.java	2012-04-16 20:45:04 UTC (rev 1973)
+++ trunk/xstream-hibernate/src/java/com/thoughtworks/xstream/hibernate/converter/HibernatePersistentSortedMapConverter.java	2012-06-08 21:16:01 UTC (rev 1974)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 XStream Committers.
+ * Copyright (C) 2011, 2012 XStream Committers.
  * All rights reserved.
  *
  * The software in this package is published under the terms of the BSD
@@ -13,16 +13,14 @@
 import com.thoughtworks.xstream.converters.ConversionException;
 import com.thoughtworks.xstream.converters.UnmarshallingContext;
 import com.thoughtworks.xstream.converters.collections.TreeMapConverter;
+import com.thoughtworks.xstream.hibernate.util.Hibernate;
 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
 import com.thoughtworks.xstream.mapper.Mapper;
 
-import org.hibernate.collection.PersistentSortedMap;
 
-
 /**
- * A converter for Hibernate's {@link PersistentSortedMap}. The converter will drop any
- * reference to the Hibernate collection and emit at serialization time an equivalent JDK
- * collection instead.
+ * A converter for Hibernate's PersistentSortedMap. The converter will drop any reference to the
+ * Hibernate collection and emit at serialization time an equivalent JDK collection instead.
  * 
  * @author J&ouml;rg Schaible
  * @since 1.4
@@ -40,7 +38,7 @@
     }
 
     public boolean canConvert(final Class type) {
-        return type == PersistentSortedMap.class;
+        return type == Hibernate.PersistentSortedMap;
     }
 
     public Object unmarshal(final HierarchicalStreamReader reader,

Modified: trunk/xstream-hibernate/src/java/com/thoughtworks/xstream/hibernate/converter/HibernatePersistentSortedSetConverter.java (1973 => 1974)


--- trunk/xstream-hibernate/src/java/com/thoughtworks/xstream/hibernate/converter/HibernatePersistentSortedSetConverter.java	2012-04-16 20:45:04 UTC (rev 1973)
+++ trunk/xstream-hibernate/src/java/com/thoughtworks/xstream/hibernate/converter/HibernatePersistentSortedSetConverter.java	2012-06-08 21:16:01 UTC (rev 1974)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 XStream Committers.
+ * Copyright (C) 2011, 2012 XStream Committers.
  * All rights reserved.
  *
  * The software in this package is published under the terms of the BSD
@@ -13,16 +13,14 @@
 import com.thoughtworks.xstream.converters.ConversionException;
 import com.thoughtworks.xstream.converters.UnmarshallingContext;
 import com.thoughtworks.xstream.converters.collections.TreeSetConverter;
+import com.thoughtworks.xstream.hibernate.util.Hibernate;
 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
 import com.thoughtworks.xstream.mapper.Mapper;
 
-import org.hibernate.collection.PersistentSortedSet;
 
-
 /**
- * A converter for Hibernate's {@link PersistentSortedSet}. The converter will drop any
- * reference to the Hibernate collection and emit at serialization time an equivalent JDK
- * collection instead.
+ * A converter for Hibernate's PersistentSortedSet. The converter will drop any reference to the
+ * Hibernate collection and emit at serialization time an equivalent JDK collection instead.
  * 
  * @author J&ouml;rg Schaible
  * @since 1.4
@@ -40,7 +38,7 @@
     }
 
     public boolean canConvert(final Class type) {
-        return type == PersistentSortedSet.class;
+        return type == Hibernate.PersistentSortedSet;
     }
 
     public Object unmarshal(final HierarchicalStreamReader reader,

Modified: trunk/xstream-hibernate/src/java/com/thoughtworks/xstream/hibernate/mapper/HibernateMapper.java (1973 => 1974)


--- trunk/xstream-hibernate/src/java/com/thoughtworks/xstream/hibernate/mapper/HibernateMapper.java	2012-04-16 20:45:04 UTC (rev 1973)
+++ trunk/xstream-hibernate/src/java/com/thoughtworks/xstream/hibernate/mapper/HibernateMapper.java	2012-06-08 21:16:01 UTC (rev 1974)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007, 2011 XStream Committers.
+ * Copyright (C) 2007, 2011, 2012 XStream Committers.
  * All rights reserved.
  *
  * The software in this package is published under the terms of the BSD
@@ -17,14 +17,9 @@
 import java.util.TreeMap;
 import java.util.TreeSet;
 
+import com.thoughtworks.xstream.hibernate.util.Hibernate;
 import com.thoughtworks.xstream.mapper.MapperWrapper;
 
-import org.hibernate.collection.PersistentBag;
-import org.hibernate.collection.PersistentList;
-import org.hibernate.collection.PersistentMap;
-import org.hibernate.collection.PersistentSet;
-import org.hibernate.collection.PersistentSortedMap;
-import org.hibernate.collection.PersistentSortedSet;
 import org.hibernate.proxy.HibernateProxy;
 
 
@@ -43,12 +38,12 @@
 
     public HibernateMapper(final MapperWrapper mapper) {
         super(mapper);
-        collectionMap.put(PersistentBag.class, ArrayList.class);
-        collectionMap.put(PersistentList.class, ArrayList.class);
-        collectionMap.put(PersistentMap.class, HashMap.class);
-        collectionMap.put(PersistentSet.class, HashSet.class);
-        collectionMap.put(PersistentSortedMap.class, TreeMap.class);
-        collectionMap.put(PersistentSortedSet.class, TreeSet.class);
+        collectionMap.put(Hibernate.PersistentBag, ArrayList.class);
+        collectionMap.put(Hibernate.PersistentList, ArrayList.class);
+        collectionMap.put(Hibernate.PersistentMap, HashMap.class);
+        collectionMap.put(Hibernate.PersistentSet, HashSet.class);
+        collectionMap.put(Hibernate.PersistentSortedMap, TreeMap.class);
+        collectionMap.put(Hibernate.PersistentSortedSet, TreeSet.class);
     }
 
     public Class defaultImplementationOf(final Class clazz) {

Added: trunk/xstream-hibernate/src/java/com/thoughtworks/xstream/hibernate/util/Hibernate.java (0 => 1974)


--- trunk/xstream-hibernate/src/java/com/thoughtworks/xstream/hibernate/util/Hibernate.java	                        (rev 0)
+++ trunk/xstream-hibernate/src/java/com/thoughtworks/xstream/hibernate/util/Hibernate.java	2012-06-08 21:16:01 UTC (rev 1974)
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2012 Joerg Schaible.
+ * All rights reserved.
+ *
+ * Created on 08.06.2012 by Joerg Schaible
+ */
+package com.thoughtworks.xstream.hibernate.util;
+
+import org.hibernate.proxy.HibernateProxy;
+
+
+/**
+ * Utility class for Hibernate support.
+ * 
+ * @author J&ouml;rg Schaible
+ * @since upcoming
+ */
+public class Hibernate {
+    public final static Class PersistentBag = loadHibernateType("org.hibernate.collection.internal.PersistentBag");
+    public final static Class PersistentList = loadHibernateType("org.hibernate.collection.internal.PersistentList");
+    public final static Class PersistentMap = loadHibernateType("org.hibernate.collection.internal.PersistentMap");
+    public final static Class PersistentSet = loadHibernateType("org.hibernate.collection.internal.PersistentSet");
+    public final static Class PersistentSortedMap = loadHibernateType("org.hibernate.collection.internal.PersistentSortedMap");
+    public final static Class PersistentSortedSet = loadHibernateType("org.hibernate.collection.internal.PersistentSortedSet");
+
+    private static Class loadHibernateType(String name) {
+        Class type = null;
+        try {
+            try {
+                type = HibernateProxy.class.getClassLoader().loadClass(name);
+            } catch (ClassNotFoundException e) {
+                type = HibernateProxy.class.getClassLoader().loadClass(
+                    name.replaceFirst("\\.internal\\.", "."));
+            }
+        } catch (ClassNotFoundException e) {
+            // not available
+        }
+        return type;
+    }
+}
Property changes on: trunk/xstream-hibernate/src/java/com/thoughtworks/xstream/hibernate/util/Hibernate.java
___________________________________________________________________

Added: svn:keywords

Added: svn:eol-style

Modified: trunk/xstream-hibernate/src/test/acceptance/hibernate/HibernateCollectionsTypeCompatibilityTest.java (1973 => 1974)


--- trunk/xstream-hibernate/src/test/acceptance/hibernate/HibernateCollectionsTypeCompatibilityTest.java	2012-04-16 20:45:04 UTC (rev 1973)
+++ trunk/xstream-hibernate/src/test/acceptance/hibernate/HibernateCollectionsTypeCompatibilityTest.java	2012-06-08 21:16:01 UTC (rev 1974)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 XStream Committers.
+ * Copyright (C) 2011, 2012 XStream Committers.
  * All rights reserved.
  *
  * The software in this package is published under the terms of the BSD
@@ -11,6 +11,8 @@
 
 package acceptance.hibernate;
 
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -18,12 +20,7 @@
 import java.util.TreeMap;
 import java.util.TreeSet;
 
-import org.hibernate.collection.PersistentBag;
-import org.hibernate.collection.PersistentList;
-import org.hibernate.collection.PersistentMap;
-import org.hibernate.collection.PersistentSet;
-import org.hibernate.collection.PersistentSortedMap;
-import org.hibernate.collection.PersistentSortedSet;
+import com.thoughtworks.xstream.hibernate.util.Hibernate;
 
 
 /**
@@ -32,28 +29,49 @@
 public class HibernateCollectionsTypeCompatibilityTest extends AbstractHibernateAcceptanceTest {
 
     public void testPersistentBag() {
-        assertXmlEquals(new ArrayList(), new PersistentBag(null, Collections.EMPTY_LIST));
+        assertXmlEquals(new ArrayList(), newHibernateCollection(Hibernate.PersistentBag, Collections.EMPTY_LIST));
     }
 
     public void testPersistentList() {
-        assertXmlEquals(new ArrayList(), new PersistentList(null, Collections.EMPTY_LIST));
+        assertXmlEquals(new ArrayList(), newHibernateCollection(Hibernate.PersistentList, Collections.EMPTY_LIST));
     }
 
     public void testPersistentMap() {
-        assertXmlEquals(new HashMap(), new PersistentMap(null, Collections.EMPTY_MAP));
+        assertXmlEquals(new HashMap(), newHibernateCollection(Hibernate.PersistentMap, Collections.EMPTY_MAP));
     }
 
     public void testPersistentSet() {
-        assertXmlEquals(new HashSet(), new PersistentSet(null, Collections.EMPTY_SET));
+        assertXmlEquals(new HashSet(), newHibernateCollection(Hibernate.PersistentSet, Collections.EMPTY_SET));
     }
 
     public void testPersistentSortedMap() {
-        assertXmlEquals(new TreeMap(), new PersistentSortedMap(null, new TreeMap()));
+        assertXmlEquals(new TreeMap(), newHibernateCollection(Hibernate.PersistentSortedMap, new TreeMap()));
     }
 
     public void testPersistentSortedSet() {
-        assertXmlEquals(new TreeSet(), new PersistentSortedSet(null, new TreeSet()));
+        assertXmlEquals(new TreeSet(), newHibernateCollection(Hibernate.PersistentSortedSet, new TreeSet()));
     }
+    
+    private Object newHibernateCollection(Class type, Object secondArg) {
+        Object instance = null;
+        Constructor[] ctors = type.getConstructors();
+        for(int i = 0; i < ctors.length; ++i) {
+            if (ctors[i].getParameterTypes().length == 2) {
+                try {
+                    instance = ctors[i].newInstance(new Object[]{null, secondArg});
+                } catch (InstantiationException e) {
+                    e.printStackTrace();
+                } catch (IllegalAccessException e) {
+                    e.printStackTrace();
+                } catch (InvocationTargetException e) {
+                    e.printStackTrace();
+                }
+                break;
+            }
+        }
+        assertNotNull(instance);
+        return instance;
+    }
 
     private void assertXmlEquals(Object reference, Object hibernateCollection) {
         final String expectedXml = xstream.toXML(reference);

Modified: trunk/xstream-hibernate/src/test/acceptance/hibernate/HibernateReferenceTest.java (1973 => 1974)


--- trunk/xstream-hibernate/src/test/acceptance/hibernate/HibernateReferenceTest.java	2012-04-16 20:45:04 UTC (rev 1973)
+++ trunk/xstream-hibernate/src/test/acceptance/hibernate/HibernateReferenceTest.java	2012-06-08 21:16:01 UTC (rev 1974)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 XStream Committers.
+ * Copyright (C) 2011, 2012 XStream Committers.
  * All rights reserved.
  *
  * The software in this package is published under the terms of the BSD
@@ -38,11 +38,15 @@
     }
 
     protected void tearDown() {
-        final Session session = getSessionFactory().getCurrentSession();
-        session.beginTransaction();
-        final Division div = (Division)session.createQuery("from Division").uniqueResult();
-        session.delete(div);
-        session.getTransaction().commit();
+        try {
+            final Session session = getSessionFactory().getCurrentSession();
+            session.beginTransaction();
+            final Division div = (Division)session.createQuery("from Division").uniqueResult();
+            session.delete(div);
+            session.getTransaction().commit();
+        } catch (RuntimeException e) {
+            e.printStackTrace();
+        }
     }
 
     public void testObjectGraphWithReferences() {
@@ -56,6 +60,7 @@
         session.beginTransaction();
         final Division loaded = (Division)session.createQuery("from Division").uniqueResult();
         final String loadedXml = xstream.toXML(loaded);
+        session.flush();
         session.getTransaction().commit();
         assertEquals(expectedXml, persistedXml);
         assertEquals(expectedXml, loadedXml);
@@ -72,6 +77,7 @@
         final Site site = person.getSite();
         assertTrue(HibernateProxy.class.isAssignableFrom(site.getClass()));
         final String loadedXml = xstream.toXML(site);
+        session.flush();
         session.getTransaction().commit();
 
         final String expectedXml = ""
@@ -117,6 +123,7 @@
         session.save(site);
         new Person("Tom", dep, site);
         session.save(div);
+        session.flush();
         session.getTransaction().commit();
         return div;
     }

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to