mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#2203 - Support use of Java Record type with @Entity, @Embeddable @IdClass
Add tests for EmbeddedId use of record type
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package org.example.records;
|
||||
|
||||
import io.ebean.Model;
|
||||
|
||||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Entity
|
||||
public class UserRole extends Model {
|
||||
|
||||
@EmbeddedId
|
||||
final UserRoleId id;
|
||||
|
||||
String note;
|
||||
|
||||
@Version
|
||||
long version;
|
||||
|
||||
public UserRole(UserRoleId id, String note) {
|
||||
this.id = id;
|
||||
this.note = note;
|
||||
}
|
||||
|
||||
public UserRoleId getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getNote() {
|
||||
return note;
|
||||
}
|
||||
|
||||
public long getVersion() {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.example.records;
|
||||
|
||||
import javax.persistence.Embeddable;
|
||||
|
||||
@Embeddable
|
||||
public record UserRoleId(Integer userId, String roleId) {
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package org.example.records;
|
||||
|
||||
import org.example.records.query.QUserRole;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class UserRoleTest {
|
||||
|
||||
final UserRoleId id = new UserRoleId(42, "R7");
|
||||
|
||||
@Test
|
||||
void id_equals() {
|
||||
assertThat(id).isEqualTo(new UserRoleId(42, "R7"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void id_notEquals() {
|
||||
assertThat(id).isNotEqualTo(new UserRoleId(43, "R7"));
|
||||
assertThat(id).isNotEqualTo(new UserRoleId(42, "R8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void insert_query() {
|
||||
|
||||
var userRole = new UserRole(id, "hello");
|
||||
userRole.save();
|
||||
|
||||
UserRole found = new QUserRole()
|
||||
.id.eq(new UserRoleId(42, "R7"))
|
||||
.findOne();
|
||||
|
||||
UserRoleId id1 = found.getId();
|
||||
assertThat(id1).isEqualTo(id);
|
||||
assertThat(id1.userId()).isEqualTo(42);
|
||||
assertThat(id1.roleId()).isEqualTo("R7");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user