-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathindex.html
More file actions
127 lines (96 loc) · 2.3 KB
/
index.html
File metadata and controls
127 lines (96 loc) · 2.3 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<html>
<head>
<title>First entity | Intro | Ebean</title>
<meta name="layout" content="_layout2/base-docs.html"/>
<meta name="bread1" content="Introduction" href="/docs/intro/"/>
<meta name="bread2" content="First entity" href="/docs/intro/first-entity"/>
<#assign n0_intro="active">
<#assign n1_firstentity="active">
</head>
<body>
<h2>First Entity</h2>
<p>
Create a package <code>org.example.domain</code> and in that create an entity bean
like <code>Customer.java</code>
</p>
<#include "/_common/lang-buttons.html">
<div class="code-java">
<pre content="java">
package org.example.domain;
import jakarata.persistence.Id;
import jakarata.persistence.Entity;
@Entity
public class Customer {
@Id
long id;
String name;
// getters and setters
}
</pre>
</div>
<div class="code-kt">
<pre content="kotlin">
package org.example.domain
import jakarata.persistence.Entity
import jakarata.persistence.Id
@Entity
class Customer {
@Id
var id: Long = 0
var name: String? = null
}
</pre>
</div>
<h2>First Test</h2>
<p>
Create a test in <code>src/test</code> like <code>CustomerTest.java</code>
</p>
<#include "/_common/lang-buttons.html">
<div class="code-java">
<pre content="java">
package org.example.domain;
import org.junit.Test;
import io.ebean.DB;
import io.ebean.Database;
public class CustomerTest {
@Test
public void insertFindDelete() {
Customer customer = new Customer();
customer.setName("Hello world");
// insert the customer in the DB
DB.save(customer);
// Find by Id
Customer foundHello = database.find(Customer.class, 1);
// delete the customer
DB.delete(customer);
}
}
</pre>
</div>
<div class="code-kt">
<pre content="kotlin">
package org.example.domain
import io.ebean.DB
import org.junit.Test
class CustomerTest {
@Test
fun insert_update_delete() {
val customer = Customer()
customer.name = "Hello entity bean"
// insert
DB.save(customer)
// find by Id
var found = DB.find(Customer::class.java, 1);
DB.delete(found);
}
}
</pre>
</div>
<h2>Run test</h2>
<p>
Run the test via the IDE and via Maven or Gradle. Check the logs to confirm you see the
<code>DDL</code> and <code>SQL</code> that you expect.
</p>
<@next_edit "Model" "/docs/intro/first-entity/model" "/docs/intro/first-entity/index.html"/>
</body>
</html>