First Entity
Create a package org.example.domain
and in that create an entity bean
like Customer.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
}
package org.example.domain
import jakarata.persistence.Entity
import jakarata.persistence.Id
@Entity
class Customer {
@Id
var id: Long = 0
var name: String? = null
}
First Test
Create a test in src/test
like CustomerTest.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);
}
}
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);
}
}
Run test
Run the test via the IDE and via Maven or Gradle. Check the logs to confirm you see the
DDL
and SQL
that you expect.