29 @GeneratedValue
30 private long id;
31
32 /**
33 * Annotates the field to carry a TIMESTAMP value in the database column.
34 * The column name is different than the default value of timestamp
35 * because many databases will reserve that word.
36 *
37 * The field is immutable by application (no setter method) and set on
38 * construction with current time.
39 */
40 @Temporal(TemporalType.TIMESTAMP)
41 @Column(name="createdOn")
42 private Date timestamp;
43
44 /**
45 * Does not annotate but the field will be persisted nevertheless by
46 * convention of String and primitive types being persistent by default.
47 */
48 private String body;
49
50 protected Message() {
51 this("");
52 }
53
54 public Message(String body) {
55 timestamp = new Date();
56 this.body = (body == null) ? "" : body;
57 }
58
59 public long getId() {
60 return id;
61 }
62
63 public String getBody() {
64 return body;
65 }
66
67 public Date getTimestamp() {
68 return timestamp;
69 }
70 } 因为我们使用了O-R映射注释表示Message类的实例与数据库表和列之间的映射关系(或者说是哪个域值能够作为Message实例的主标识符),所以JPA依赖关系已经移入这个Java类中。这些映射信息可以移到一个单独的orm.xml中,从而使这个类恢复Pure Old Java Object (POJO)状态并完善这种不明确的更接近域对象模型的方法。
编码前的测试
JUnit测试用例通过JNDI查找与服务进行交互并检验两个服务方法返回的是否为预期的结果。
文章来源于领测软件测试网 https://www.ltesting.net/