Skip to content

Commit c8cb197

Browse files
committed
Update Hibernate support to latest version of 7.x line. Closes #346.
1 parent 18f1b4d commit c8cb197

File tree

4 files changed

+57
-16
lines changed

4 files changed

+57
-16
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@
12131213
<version.org.codehaus.woodstox.asl>3.2.7</version.org.codehaus.woodstox.asl>
12141214
<version.org.hibernate.core>5.6.15.Final</version.org.hibernate.core>
12151215
<version.org.hibernate.envers>${version.org.hibernate.core}</version.org.hibernate.envers>
1216-
<version.org.hibernate.orm.core>6.6.28.Final</version.org.hibernate.orm.core>
1216+
<version.org.hibernate.orm.core>7.1.0.Final</version.org.hibernate.orm.core>
12171217
<version.org.hibernate.orm.envers>${version.org.hibernate.orm.core}</version.org.hibernate.orm.envers>
12181218
<version.org.jdom>1.1.3</version.org.jdom>
12191219
<version.org.jdom2>2.0.5</version.org.jdom2>

xstream-distribution/src/content/changes.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ <h2>Minor changes</h2>
5050

5151
<ul>
5252
<li>GHI:#347: PrettyPrintWriter exposes internal classes of com.thoughtworks.xstream.core.util.</li>
53+
<li>GHPR:#346: XStream supports now Hibernate from 3.x up to current version 7.1.0.</li>
5354
</ul>
5455

5556
<h2>API changes</h2>

xstream-hibernate/pom.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
</description>
2424

2525
<profiles>
26+
<profile>
27+
<id>jdk11-ge-jdk16</id>
28+
<activation>
29+
<jdk>[11,17)</jdk>
30+
</activation>
31+
<properties>
32+
<version.org.hibernate.orm.core>6.6.28.Final</version.org.hibernate.orm.core>
33+
</properties>
34+
</profile>
2635
<profile>
2736
<id>jdk11-ge</id>
2837
<activation>
@@ -239,7 +248,7 @@
239248
</dependencies>
240249

241250
<properties>
242-
<bundle.version.hibernate>[3,7)</bundle.version.hibernate>
251+
<bundle.version.hibernate>[3,8)</bundle.version.hibernate>
243252
<bundle.export.package>!com.thoughtworks.xstream.hibernate.util,com.thoughtworks.xstream.hibernate.*;-noimport:=true</bundle.export.package>
244253
<bundle.import.package>
245254
org.hibernate.proxy;resolution:=optional;version="${bundle.version.hibernate}",

xstream-hibernate/src/test/acceptance/hibernate/HibernateReferenceTest.java

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2011, 2012 XStream Committers.
2+
* Copyright (C) 2011, 2012, 2025 XStream Committers.
33
* All rights reserved.
44
*
55
* The software in this package is published under the terms of the BSD
@@ -17,6 +17,8 @@
1717
import acceptance.hibernate.reference.Person;
1818
import acceptance.hibernate.reference.Site;
1919

20+
import java.lang.reflect.Method;
21+
2022
import org.hibernate.Session;
2123
import org.hibernate.proxy.HibernateProxy;
2224

@@ -27,6 +29,38 @@
2729
*/
2830
public class HibernateReferenceTest extends AbstractHibernateAcceptanceTest {
2931

32+
private final static Method persist;
33+
private final static Method remove;
34+
static {
35+
Method method;
36+
try {
37+
method = Session.class.getMethod("save", new Class[]{Object.class});
38+
} catch (Exception e1) {
39+
try {
40+
// Available since Hibernate 6.0
41+
method = Session.class.getMethod("persist", new Class[]{Object.class});
42+
} catch (Exception e2) {
43+
throw new ExceptionInInitializerError("Cannot find method in "
44+
+ Session.class.getName()
45+
+ " to persist/save objects");
46+
}
47+
}
48+
persist = method;
49+
try {
50+
method = Session.class.getMethod("delete", new Class[]{Object.class});
51+
} catch (Exception e1) {
52+
try {
53+
// Available since Hibernate 6.0
54+
method = Session.class.getMethod("remove", new Class[]{Object.class});
55+
} catch (Exception e2) {
56+
throw new ExceptionInInitializerError("Cannot find method in "
57+
+ Session.class.getName()
58+
+ " to remove/delete objects");
59+
}
60+
}
61+
remove = method;
62+
}
63+
3064
protected void setUp() throws Exception {
3165
super.setUp();
3266
// don't write the primary keys in this test
@@ -42,14 +76,14 @@ protected void tearDown() {
4276
final Session session = getSessionFactory().getCurrentSession();
4377
session.beginTransaction();
4478
final Division div = (Division)session.createQuery("from Division").uniqueResult();
45-
session.delete(div);
79+
remove.invoke(session, new Object[]{div});
4680
session.getTransaction().commit();
47-
} catch (RuntimeException e) {
81+
} catch (Exception e) {
4882
e.printStackTrace();
4983
}
5084
}
5185

52-
public void testObjectGraphWithReferences() {
86+
public void testObjectGraphWithReferences() throws Exception {
5387
final Division memory = setupNonpersistentDivision();
5488
final Division persisted = setupPersistentDivision();
5589

@@ -66,7 +100,7 @@ public void testObjectGraphWithReferences() {
66100
assertEquals(expectedXml, loadedXml);
67101
}
68102

69-
public void testLazyProxyWithReferences() {
103+
public void testLazyProxyWithReferences() throws Exception {
70104
setupPersistentDivision();
71105

72106
final Session session = getSessionFactory().getCurrentSession();
@@ -108,21 +142,18 @@ public void testLazyProxyWithReferences() {
108142
/**
109143
* Create the object within a Hibernate session and persist it.
110144
*/
111-
private Division setupPersistentDivision() {
145+
private Division setupPersistentDivision() throws Exception {
112146
final Session session = getSessionFactory().getCurrentSession();
113147
session.beginTransaction();
114148
final Division div = new Division("Div1");
115149
final Department dep = new Department("Dep1", div);
116150
final Site site = new Site("Site1");
117-
/*
118-
* This save is necessitated by the fact that Hibernate's transitive persistence is
119-
* depth-first and does not do a full graph analysis. Therefore it would be possible for
120-
* Hibernate to try to save the person record before the site record, which would throw
121-
* an error if the person.site FK is non-nullable.
122-
*/
123-
session.save(site);
151+
/* This save is necessitated by the fact that Hibernate's transitive persistence is depth-first and does not do
152+
* a full graph analysis. Therefore it would be possible for Hibernate to try to save the person record before
153+
* the site record, which would throw an error if the person.site FK is non-nullable. */
154+
persist.invoke(session, new Object[]{site});
124155
new Person("Tom", dep, site);
125-
session.save(div);
156+
persist.invoke(session, new Object[]{div});
126157
session.flush();
127158
session.getTransaction().commit();
128159
return div;

0 commit comments

Comments
 (0)