#2692 - [querybean generation] Compile error, incorrect generation with nested inner class/record @Embeddable and @IdClass

This commit is contained in:
Rob Bygrave committed 2022-05-16 18:48:42 +12:00
1 parent b7d6374370
commit 9dea51b7a0
13 files changed
+316 -68

No files matched your search

@@ -0,0 +1,69 @@
package org.example.domain;
import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import java.util.Objects;
@Entity
@IdClass(MyInner.ID.class)
public class MyInner {
@Embeddable
public static class ID {
final long id;
final String one;
public ID(long id, String one) {
this.id = id;
this.one = one;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ID id1 = (ID) o;
return id == id1.id && one.equals(id1.one);
}
@Override
public int hashCode() {
return Objects.hash(id, one);
}
}
@Id
long id;
@Id
String one;
String description;
public long id() {
return id;
}
public MyInner id(long id) {
this.id = id;
return this;
}
public String one() {
return one;
}
public MyInner one(String beanOne) {
this.one = beanOne;
return this;
}
public String description() {
return description;
}
public MyInner description(String description) {
this.description = description;
return this;
}
}
@@ -0,0 +1,30 @@
package org.querytest;
import io.ebean.DB;
import org.example.domain.MyInner;
import org.example.domain.query.QMyInner;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
class MyInnerTest {
@Test
void insert_and_find() {
MyInner myInner = new MyInner()
.id(42).one("one").description("foo");
DB.save(myInner);
MyInner found = DB.find(MyInner.class, new MyInner.ID(42, "one"));
assertThat(found).isNotNull();
MyInner found2 = new QMyInner()
.id.eq(42)
.one.eq("one")
.findOne();
assertThat(found2).isNotNull();
}
}