#2154 - QueryBeans: TargetEntity is not evaluated during bean generation resulting in bad query beans

This commit is contained in:
Robin Bygrave committed 2021-02-10 15:10:03 +13:00
1 parent ab9cdd8f5b
commit 53aacabce7
6 files changed
+134 -27

No files matched your search

@@ -0,0 +1,35 @@
package org.example.domain;
import org.example.domain.target.ACity;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import java.util.List;
@Entity
public class AreaImpl {
@Id
long id;
@OneToMany(targetEntity = CityImpl.class, cascade = CascadeType.ALL)
List<ACity> cities;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public List<ACity> getCities() {
return cities;
}
public void setCities(List<ACity> cities) {
this.cities = cities;
}
}
@@ -0,0 +1,36 @@
package org.example.domain;
import org.example.domain.target.ACity;
import org.example.domain.target.ACountry;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
@Entity
public class CityImpl implements ACity {
@Id
long id;
String name;
@ManyToOne(targetEntity = CountryImpl.class)
ACountry country;
@Override
public long id() {
return id;
}
@Override
public String name() {
return null;
}
@Override
public ACountry country() {
return country;
}
}
@@ -0,0 +1,18 @@
package org.example.domain;
import org.example.domain.target.ACountry;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class CountryImpl implements ACountry {
@Id
String code;
@Override
public String code() {
return code;
}
}
@@ -0,0 +1,24 @@
package org.querytest;
import org.example.domain.query.QAreaImpl;
import org.example.domain.query.QCityImpl;
import org.junit.Test;
public class TargetTest {
@Test
public void test_oneToMany() {
new QAreaImpl()
.cities.fetch()
.findList();
}
@Test
public void test_manyToOne() {
new QCityImpl()
.country.fetch()
.findList();
}
}