mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Follow up #3223 - Add @IdClass example test
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package org.tests.model.composite;
|
||||
|
||||
|
||||
import io.ebean.annotation.Index;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@IdClass(DataWithFormulaKey.class)
|
||||
@Entity
|
||||
public class Data2WithFormula {
|
||||
|
||||
@Id
|
||||
private UUID mainId;
|
||||
|
||||
@Id
|
||||
private String metaKey;
|
||||
|
||||
@Id
|
||||
private Integer valueIndex;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "main_id", insertable = false, nullable = false)
|
||||
private Data2WithFormulaMain main;
|
||||
|
||||
@Index
|
||||
private String stringValue;
|
||||
|
||||
public UUID mainId() {
|
||||
return mainId;
|
||||
}
|
||||
|
||||
public void setMainId(UUID mainId) {
|
||||
this.mainId = mainId;
|
||||
}
|
||||
|
||||
public String getMetaKey() {
|
||||
return metaKey;
|
||||
}
|
||||
|
||||
public void setMetaKey(String metaKey) {
|
||||
this.metaKey = metaKey;
|
||||
}
|
||||
|
||||
public Integer getValueIndex() {
|
||||
return valueIndex;
|
||||
}
|
||||
|
||||
public void setValueIndex(Integer valueIndex) {
|
||||
this.valueIndex = valueIndex;
|
||||
}
|
||||
|
||||
public String getStringValue() {
|
||||
return stringValue;
|
||||
}
|
||||
|
||||
public void setStringValue(String stringValue) {
|
||||
this.stringValue = stringValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package org.tests.model.composite;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity
|
||||
public class Data2WithFormulaMain {
|
||||
|
||||
@Id
|
||||
private UUID id;
|
||||
|
||||
private String title;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "main")
|
||||
private List<Data2WithFormula> metaData;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public List<Data2WithFormula> getMetaData() {
|
||||
return metaData;
|
||||
}
|
||||
|
||||
public void setMetaData(List<Data2WithFormula> metaData) {
|
||||
this.metaData = metaData;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.tests.model.composite;
|
||||
|
||||
import io.ebean.DB;
|
||||
import io.ebean.test.LoggedSql;
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
class TestData2WithFormula extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
void test1() {
|
||||
|
||||
Data2WithFormulaMain main = new Data2WithFormulaMain();
|
||||
main.setId(UUID.randomUUID());
|
||||
main.setTitle("Main");
|
||||
|
||||
Data2WithFormula data = new Data2WithFormula();
|
||||
data.setMainId(main.getId());
|
||||
data.setMetaKey("meta");
|
||||
data.setValueIndex(42);
|
||||
data.setStringValue("SomeValue");
|
||||
main.setMetaData(List.of(data));
|
||||
|
||||
LoggedSql.start();
|
||||
DB.save(main);
|
||||
List<String> sqls = LoggedSql.stop();
|
||||
|
||||
assertThat(sqls).hasSize(3);
|
||||
assertThat(sqls.get(0)).contains("insert into data2_with_formula_main (id, title) values (?,?);"); // main
|
||||
assertThat(sqls.get(1)).contains("insert into data2_with_formula (main_id, meta_key, value_index, string_value) values (?,?,?,?)"); // main
|
||||
assertThat(sqls.get(2)).contains("-- bind");
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user