Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.

Commit 2f989dc

Browse files
committed
Merge pull request #51 from jateeter/master
Attempted work-around for NoResultException.x.TransactionRollback error
2 parents f3d3d02 + dbbdc15 commit 2f989dc

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/main/java/org/energyos/espi/common/repositories/jpa/UsagePointRepositoryImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ public void createOrReplaceByUUID(UsagePoint usagePoint) {
106106
if (existingUsagePoint.getUpLink() != null) {
107107
usagePoint.setUpLink(existingUsagePoint.getUpLink());
108108
}
109-
109+
usagePoint.setPublished(existingUsagePoint.getPublished());
110+
usagePoint.setUpdated(existingUsagePoint.getUpdated());
111+
110112
em.merge(usagePoint);
111113
} catch (NoResultException e) {
112114
usagePoint.setPublished(new GregorianCalendar());

src/main/java/org/energyos/espi/common/service/ResourceService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ List<IdentifiedObject> findByAllParentsHref(String relatedHref,
1616

1717
<T> T findByUUID(UUID uuid, Class<T> clazz);
1818

19+
<T extends IdentifiedObject> T testById(Long id, Class<T> clazz);
20+
1921
<T extends IdentifiedObject> T findById(Long id, Class<T> clazz);
2022

2123
<T extends IdentifiedObject> List<Long> findAllIds(Class<T> clazz);

src/main/java/org/energyos/espi/common/service/impl/ResourceServiceImpl.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,15 @@ public <T> T findByUUID(UUID uuid, Class<T> clazz) {
5656
return repository.findByUUID(uuid, clazz);
5757
}
5858

59-
@Override
59+
// the following is used to query for the existence of the object in the DB within
60+
// a closed transactional space. Callers will need a Catch on the NoResultExecption for failure.
61+
@Override
6062
@Transactional( readOnly = true)
63+
public <T extends IdentifiedObject> T testById(Long id, Class<T> clazz) {
64+
return repository.findById(id, clazz);
65+
}
66+
67+
@Override
6168
public <T extends IdentifiedObject> T findById(Long id, Class<T> clazz) {
6269
return repository.findById(id, clazz);
6370
}
@@ -127,4 +134,6 @@ public void setRepository(ResourceRepository repository) {
127134
}
128135

129136

137+
138+
130139
}

0 commit comments

Comments
 (0)