Skip to content

Commit 9963459

Browse files
authored
DRYD-2082: Update Hibernate (#524)
* Update hibernate to 5.6.15.Final to match nuxeo * Move annotations on created/updatedAt to fields * Create DateAdapter for XML serialization * Prefer javax.transaction connection properties * Remove unused connection properties
1 parent 047dce8 commit 9963459

40 files changed

Lines changed: 409 additions & 674 deletions

File tree

pom.xml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<!-- Managed Dependency Versions -->
2020
<aspectj.version>1.7.4</aspectj.version>
2121
<chemistry.opencmis.version.nx>0.12.0-NX2</chemistry.opencmis.version.nx>
22+
<hibernate.version>5.6.15.Final</hibernate.version>
2223
<jackson.version>2.14.3</jackson.version>
2324
<jaxb-runtime.version>4.0.5</jaxb-runtime.version>
2425
<jvnet.jaxb.version>4.0.12</jvnet.jaxb.version>
@@ -1187,26 +1188,36 @@
11871188
</dependency>
11881189
<dependency>
11891190
<groupId>javax.persistence</groupId>
1190-
<artifactId>persistence-api</artifactId>
1191-
<version>1.0</version>
1191+
<artifactId>javax.persistence-api</artifactId>
1192+
<version>2.2</version>
1193+
</dependency>
1194+
<dependency>
1195+
<groupId>org.hibernate</groupId>
1196+
<artifactId>hibernate-core</artifactId>
1197+
<version>${hibernate.version}</version>
1198+
<exclusions>
1199+
<exclusion>
1200+
<groupId>javax.xml.bind</groupId>
1201+
<artifactId>jaxb-api</artifactId>
1202+
</exclusion>
1203+
</exclusions>
11921204
</dependency>
11931205
<dependency>
11941206
<groupId>org.hibernate</groupId>
11951207
<artifactId>hibernate-entitymanager</artifactId>
1196-
<version>3.4.0.GA</version>
1208+
<version>${hibernate.version}</version>
11971209
<exclusions>
11981210
<!-- Exclude dom4j:dom4j so we can upgrade to org.dom4j:dom4j. -->
11991211
<exclusion>
12001212
<groupId>dom4j</groupId>
12011213
<artifactId>dom4j</artifactId>
12021214
</exclusion>
1215+
<exclusion>
1216+
<groupId>javax.xml.bind</groupId>
1217+
<artifactId>jaxb-api</artifactId>
1218+
</exclusion>
12031219
</exclusions>
12041220
</dependency>
1205-
<dependency>
1206-
<groupId>org.hibernate</groupId>
1207-
<artifactId>hibernate-c3p0</artifactId>
1208-
<version>3.6.10.Final</version>
1209-
</dependency>
12101221

12111222
<dependency>
12121223
<groupId>org.postgresql</groupId>

services/JaxRsServiceProvider/src/main/resources/META-INF/persistence.xml

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<persistence version="1.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
3-
http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
4-
xmlns="http://java.sun.com/xml/ns/persistence"
5-
xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
6-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
2+
<persistence version="2.0"
3+
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
4+
xmlns="http://java.sun.com/xml/ns/persistence"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
76
<persistence-unit name="org.collectionspace.services">
87
<provider>org.hibernate.ejb.HibernatePersistence</provider>
98
<!-- Until our JNDI issue with Nuxeo is resolved, we can't use this datasource element
@@ -12,27 +11,25 @@
1211
<class>org.collectionspace.services.account.AccountsCommon</class>
1312
<class>org.collectionspace.services.account.Tenant</class>
1413
<class>org.collectionspace.services.account.AccountTenant</class>
15-
<class>org.collectionspace.services.account.Status</class>
14+
<class>org.collectionspace.services.account.Status</class>
1615
<class>org.collectionspace.services.authentication.User</class>
1716
<class>org.collectionspace.services.authentication.Token</class>
1817
<class>org.collectionspace.services.authorization.perms.Permission</class>
1918
<class>org.collectionspace.services.authorization.perms.PermissionAction</class>
2019
<class>org.collectionspace.services.authorization.PermissionRoleRel</class>
2120
<class>org.collectionspace.services.authorization.Role</class>
2221
<class>org.collectionspace.services.authorization.AccountRoleRel</class>
23-
22+
2423
<properties>
25-
<property name="hibernate.dialect" value="${db.dialect}"/>
24+
<property name="hibernate.dialect" value="${db.dialect}"/>
2625
<property name="hibernate.max_fetch_depth" value="3"/>
27-
<!-- Until our JNDI issue with Nuxeo is resolved, we have to use these JDBC properties rather than a datasource -->
28-
<property name="hibernate.connection.driver_class" value="${db.jdbc.driver.class}"/>
29-
<property name="hibernate.connection.username" value="${db.cspace.user}"/>
30-
<property name="hibernate.connection.password" value="${db.cspace.user.password}"/>
31-
<property name="hibernate.connection.url" value="${db.jdbc.cspace.url.encoded}"/>
32-
<!--property name="hibernate.hbm2ddl.auto" value="create-drop"/-->
33-
34-
<property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider"/>
35-
<property name="hibernate.c3p0.max_size" value="8"/>
26+
<!-- Until our JNDI issue with Nuxeo is resolved, we have to use these JDBC properties rather than a datasource -->
27+
<property name="javax.persistence.jdbc.driver" value="${db.jdbc.driver.class}"/>
28+
<property name="javax.persistence.jdbc.user" value="${db.cspace.user}"/>
29+
<property name="javax.persistence.jdbc.password" value="${db.cspace.user.password}"/>
30+
<property name="javax.persistence.jdbc.url" value="${db.jdbc.cspace.url.encoded}"/>
31+
<!-- Same as auth-mgt import - disable XML Mapping so that javax.xml.bind classes are not loaded -->
32+
<property name="hibernate.xml_mapping_enabled" value="false" />
3633
</properties>
3734

3835
</persistence-unit>

services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void create(String testName) throws Exception {
6161
account.setStatus(Status.ACTIVE);
6262
id = UUID.randomUUID().toString();
6363
account.setCsid(id);
64-
account.setCreatedAtItem(new Date());
64+
account.setCreatedAt(new Date());
6565
AccountTenant tenant = new AccountTenant();
6666
tenant.setTenantId("123");
6767
List<AccountTenant> tList = new ArrayList<AccountTenant>();

services/account/jaxb/pom.xml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,12 @@
1515
<dependencies>
1616
<dependency>
1717
<groupId>javax.persistence</groupId>
18-
<artifactId>persistence-api</artifactId>
18+
<artifactId>javax.persistence-api</artifactId>
1919
</dependency>
2020
<dependency>
2121
<groupId>jakarta.xml.bind</groupId>
2222
<artifactId>jakarta.xml.bind-api</artifactId>
2323
</dependency>
24-
<dependency>
25-
<groupId>org.jvnet.jaxb</groupId>
26-
<artifactId>hyperjaxb3-ejb-runtime</artifactId>
27-
<version>4.0.12</version>
28-
</dependency>
2924

3025
<dependency>
3126
<groupId>org.collectionspace.services</groupId>

services/account/jaxb/src/main/java/org/collectionspace/services/account/AccountsCommon.java

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import javax.persistence.TemporalType;
2222
import javax.persistence.Transient;
2323
import javax.persistence.UniqueConstraint;
24-
import javax.xml.datatype.XMLGregorianCalendar;
2524

2625
import jakarta.xml.bind.annotation.XmlAccessType;
2726
import jakarta.xml.bind.annotation.XmlAccessorType;
@@ -30,9 +29,9 @@
3029
import jakarta.xml.bind.annotation.XmlRootElement;
3130
import jakarta.xml.bind.annotation.XmlSchemaType;
3231
import jakarta.xml.bind.annotation.XmlType;
32+
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
33+
import org.collectionspace.services.jaxb.adapter.DateAdapter;
3334
import org.jspecify.annotations.NonNull;
34-
import org.jvnet.hyperjaxb3.xml.bind.annotation.adapters.XMLGregorianCalendarAsDateTime;
35-
import org.jvnet.hyperjaxb3.xml.bind.annotation.adapters.XmlAdapterUtils;
3635

3736

3837
@XmlAccessorType(XmlAccessType.FIELD)
@@ -108,15 +107,19 @@ public class AccountsCommon {
108107
@Column(name = "roles_protection")
109108
private String rolesProtection;
110109

111-
@Transient
110+
@Column(name = "created_at", nullable = false)
111+
@Temporal(TemporalType.TIMESTAMP)
112112
@XmlElement(required = true)
113113
@XmlSchemaType(name = "dateTime")
114-
private XMLGregorianCalendar createdAt;
114+
@XmlJavaTypeAdapter(DateAdapter.class)
115+
private Date createdAt;
115116

116-
@Transient
117+
@Column(name = "updated_at")
118+
@Temporal(TemporalType.TIMESTAMP)
117119
@XmlElement(required = true)
118120
@XmlSchemaType(name = "dateTime")
119-
private XMLGregorianCalendar updatedAt;
121+
@XmlJavaTypeAdapter(DateAdapter.class)
122+
private Date updatedAt;
120123

121124
@Transient
122125
private RoleList roleList;
@@ -221,19 +224,19 @@ public void setRolesProtection(String rolesProtection) {
221224
this.rolesProtection = rolesProtection;
222225
}
223226

224-
public XMLGregorianCalendar getCreatedAt() {
227+
public Date getCreatedAt() {
225228
return createdAt;
226229
}
227230

228-
public void setCreatedAt(XMLGregorianCalendar createdAt) {
231+
public void setCreatedAt(Date createdAt) {
229232
this.createdAt = createdAt;
230233
}
231234

232-
public XMLGregorianCalendar getUpdatedAt() {
235+
public Date getUpdatedAt() {
233236
return updatedAt;
234237
}
235238

236-
public void setUpdatedAt(XMLGregorianCalendar updatedAt) {
239+
public void setUpdatedAt(Date updatedAt) {
237240
this.updatedAt = updatedAt;
238241
}
239242

@@ -253,28 +256,6 @@ public void setCsid(String csid) {
253256
this.csid = csid;
254257
}
255258

256-
@Basic
257-
@Column(name = "created_at", nullable = false)
258-
@Temporal(TemporalType.TIMESTAMP)
259-
public Date getCreatedAtItem() {
260-
return XmlAdapterUtils.unmarshall(XMLGregorianCalendarAsDateTime.class, this.getCreatedAt());
261-
}
262-
263-
public void setCreatedAtItem(Date createdAt) {
264-
setCreatedAt(XmlAdapterUtils.marshall(XMLGregorianCalendarAsDateTime.class, createdAt));
265-
}
266-
267-
@Basic
268-
@Column(name = "updated_at")
269-
@Temporal(TemporalType.TIMESTAMP)
270-
public Date getUpdatedAtItem() {
271-
return XmlAdapterUtils.unmarshall(XMLGregorianCalendarAsDateTime.class, this.getUpdatedAt());
272-
}
273-
274-
public void setUpdatedAtItem(Date updatedAt) {
275-
setUpdatedAt(XmlAdapterUtils.marshall(XMLGregorianCalendarAsDateTime.class, updatedAt));
276-
}
277-
278259
@Override
279260
public boolean equals(Object o) {
280261
if (o == null || getClass() != o.getClass()) {

services/account/jaxb/src/main/java/org/collectionspace/services/account/Tenant.java

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@
1111
import javax.persistence.Table;
1212
import javax.persistence.Temporal;
1313
import javax.persistence.TemporalType;
14-
import javax.persistence.Transient;
15-
import javax.xml.datatype.XMLGregorianCalendar;
1614

1715
import jakarta.xml.bind.annotation.XmlAccessType;
1816
import jakarta.xml.bind.annotation.XmlAccessorType;
1917
import jakarta.xml.bind.annotation.XmlElement;
2018
import jakarta.xml.bind.annotation.XmlRootElement;
2119
import jakarta.xml.bind.annotation.XmlSchemaType;
2220
import jakarta.xml.bind.annotation.XmlType;
23-
import org.jvnet.hyperjaxb3.xml.bind.annotation.adapters.XMLGregorianCalendarAsDateTime;
24-
import org.jvnet.hyperjaxb3.xml.bind.annotation.adapters.XmlAdapterUtils;
21+
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
22+
import org.collectionspace.services.jaxb.adapter.DateAdapter;
2523

2624

2725
@XmlAccessorType(XmlAccessType.FIELD)
@@ -55,15 +53,19 @@ public class Tenant {
5553
@Column(name = "disabled", nullable = false)
5654
private boolean disabled;
5755

58-
@Transient
56+
@Column(name = "created_at", nullable = false)
57+
@Temporal(TemporalType.TIMESTAMP)
5958
@XmlElement(required = true)
6059
@XmlSchemaType(name = "dateTime")
61-
private XMLGregorianCalendar createdAt;
60+
@XmlJavaTypeAdapter(DateAdapter.class)
61+
private Date createdAt;
6262

63-
@Transient
63+
@Column(name = "updated_at")
64+
@Temporal(TemporalType.TIMESTAMP)
6465
@XmlElement(required = true)
6566
@XmlSchemaType(name = "dateTime")
66-
private XMLGregorianCalendar updatedAt;
67+
@XmlJavaTypeAdapter(DateAdapter.class)
68+
private Date updatedAt;
6769

6870
public String getId() {
6971
return id;
@@ -105,44 +107,22 @@ public void setDisabled(boolean disabled) {
105107
this.disabled = disabled;
106108
}
107109

108-
public XMLGregorianCalendar getCreatedAt() {
110+
public Date getCreatedAt() {
109111
return createdAt;
110112
}
111113

112-
public void setCreatedAt(XMLGregorianCalendar createdAt) {
114+
public void setCreatedAt(Date createdAt) {
113115
this.createdAt = createdAt;
114116
}
115117

116-
public XMLGregorianCalendar getUpdatedAt() {
118+
public Date getUpdatedAt() {
117119
return updatedAt;
118120
}
119121

120-
public void setUpdatedAt(XMLGregorianCalendar updatedAt) {
122+
public void setUpdatedAt(Date updatedAt) {
121123
this.updatedAt = updatedAt;
122124
}
123125

124-
@Basic
125-
@Column(name = "created_at", nullable = false)
126-
@Temporal(TemporalType.TIMESTAMP)
127-
public Date getCreatedAtItem() {
128-
return XmlAdapterUtils.unmarshall(XMLGregorianCalendarAsDateTime.class, this.getCreatedAt());
129-
}
130-
131-
public void setCreatedAtItem(Date createdAt) {
132-
setCreatedAt(XmlAdapterUtils.marshall(XMLGregorianCalendarAsDateTime.class, createdAt));
133-
}
134-
135-
@Basic
136-
@Column(name = "updated_at")
137-
@Temporal(TemporalType.TIMESTAMP)
138-
public Date getUpdatedAtItem() {
139-
return XmlAdapterUtils.unmarshall(XMLGregorianCalendarAsDateTime.class, this.getUpdatedAt());
140-
}
141-
142-
public void setUpdatedAtItem(Date updatedAt) {
143-
setUpdatedAt(XmlAdapterUtils.marshall(XMLGregorianCalendarAsDateTime.class, updatedAt));
144-
}
145-
146126
@Override
147127
public boolean equals(Object o) {
148128
if (o == null || getClass() != o.getClass()) {

services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void handleUpdate(DocumentWrapper<AccountsCommon> wrapDoc) throws Excepti
142142
*/
143143
private AccountsCommon merge(AccountsCommon from, AccountsCommon to) {
144144
Date now = new Date();
145-
to.setUpdatedAtItem(now);
145+
to.setUpdatedAt(now);
146146
if (from.getEmail() != null) {
147147
to.setEmail(from.getEmail());
148148
}

services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountStorageClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public String create(ServiceContext ctx,
8686
//
8787
// Now add the account to the CSpace list of accounts
8888
//
89-
account.setCreatedAtItem(new Date());
89+
account.setCreatedAt(new Date());
9090
jpaConnectionContext.persist(account);
9191
//
9292
// Finish creating related resources -e.g., account-role relationships

services/account/service/src/main/java/org/collectionspace/services/account/storage/TenantDocumentHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void handleUpdate(DocumentWrapper<Tenant> wrapDoc) throws Exception {
7676
*/
7777
private Tenant merge(Tenant from, Tenant to) {
7878
Date now = new Date();
79-
to.setUpdatedAtItem(now);
79+
to.setUpdatedAt(now);
8080
// The only thing we allow changing at this point are the 'disabled' and 'authoritiesInitialized' flags
8181
to.setDisabled(from.isDisabled());
8282
to.setAuthoritiesInitialized(from.isAuthoritiesInitialized());

services/account/service/src/main/java/org/collectionspace/services/account/storage/TenantStorageClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public String create(ServiceContext ctx,
7373
new DocumentWrapperImpl<Tenant>(tenant);
7474
handler.handle(Action.CREATE, wrapDoc);
7575
jpaConnectionContext.beginTransaction();
76-
tenant.setCreatedAtItem(new Date());
76+
tenant.setCreatedAt(new Date());
7777
jpaConnectionContext.persist(tenant);
7878
handler.complete(Action.CREATE, wrapDoc);
7979
jpaConnectionContext.commitTransaction();

0 commit comments

Comments
 (0)