Skip to content

Commit 979f2ef

Browse files
authored
Java/ninja revert transactional change so data persists (#3217)
* Java/ninja revert transactional change so data persists * Use transactional to persist but only once per update * Update HelloDbController.java
1 parent 1cee232 commit 979f2ef

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

frameworks/Java/ninja-standalone/src/main/java/controllers/HelloDbController.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import com.google.inject.Inject;
1212
import com.google.inject.Singleton;
13+
import com.google.inject.persist.Transactional;
1314
import ninja.jpa.UnitOfWork;
1415
import ninja.params.Param;
1516

@@ -62,12 +63,17 @@ public Result update(@Param("queries") Integer queries) {
6263
// now update stuff:
6364
for (World world : worlds) {
6465
world.randomNumber = ThreadLocalRandom.current().nextInt(DB_ROWS) + 1;
65-
worldDao.put(world);
66+
this.updateWorld(world);
6667
}
6768

6869
return Results.json().render(worlds);
6970
}
7071

72+
@Transactional
73+
public void updateWorld(World world) {
74+
worldDao.put(world);
75+
}
76+
7177
private World getRandomWorld() {
7278
return worldDao.get(ThreadLocalRandom.current().nextInt(DB_ROWS) + 1);
7379
}

0 commit comments

Comments
 (0)