-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyService.java
57 lines (37 loc) · 1.44 KB
/
MyService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package org.acme;
import org.jboss.logging.Logger;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;
import java.util.Date;
@ApplicationScoped
public class MyService {
private static final Logger LOG = Logger.getLogger(MyService.class);
@Inject
private MyEntityRepository repository;
public MyEntity transactionTest() {
MyEntity entity = new MyEntity();
entity.name = "Name";
entity.startingTime = new Date().getTime();
entity = this.persist(entity);
LOG.warn("After persist: " + MyEntity.findAll().list().get(0));
entity = this.update(entity);
LOG.warn("After update method: " + MyEntity.findAll().list().get(0));
MyEntity entityFromDB = (MyEntity) MyEntity.findAll().list().get(0);
if(entityFromDB.endingTime == null) {
throw new RuntimeException("Why is the value of entity.endingTime (from DB) null at this point?");
}
return entity;
}
@Transactional
private MyEntity persist(MyEntity obj) {
return repository.create(obj);
}
@Transactional
private MyEntity update(MyEntity obj) {
obj.endingTime = new Date().getTime();
obj = repository.update(obj);
LOG.warn("Inside update method: " + MyEntity.findAll().list().get(0));
return obj;
}
}