mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-19 23:02:24 +00:00
#2154 - QueryBeans: TargetEntity is not evaluated during bean generation resulting in bad query beans
This commit is contained in:
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
-18
@@ -303,12 +303,19 @@ class ProcessingContext implements Constants {
|
|||||||
return new PropertyTypeEnum(fullType, Split.shortName(fullType));
|
return new PropertyTypeEnum(fullType, Split.shortName(fullType));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// look for targetEntity annotation attribute
|
||||||
|
final String targetEntity = readTargetEntity(field);
|
||||||
|
if (targetEntity != null) {
|
||||||
|
final TypeElement element = elementUtils.getTypeElement(targetEntity);
|
||||||
|
if (isEntityOrEmbedded(element)) {
|
||||||
|
return createPropertyTypeAssoc(typeDef(element.asType()));
|
||||||
|
}
|
||||||
|
}
|
||||||
if (isEntityOrEmbedded(fieldType)) {
|
if (isEntityOrEmbedded(fieldType)) {
|
||||||
// public QAssocContact<QCustomer> contacts;
|
// public QAssocContact<QCustomer> contacts;
|
||||||
return createPropertyTypeAssoc(typeDef(typeMirror));
|
return createPropertyTypeAssoc(typeDef(typeMirror));
|
||||||
}
|
}
|
||||||
|
|
||||||
PropertyType result = null;
|
|
||||||
if (typeMirror.getKind() == TypeKind.DECLARED) {
|
if (typeMirror.getKind() == TypeKind.DECLARED) {
|
||||||
DeclaredType declaredType = (DeclaredType) typeMirror;
|
DeclaredType declaredType = (DeclaredType) typeMirror;
|
||||||
List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
|
List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
|
||||||
@@ -319,16 +326,7 @@ class ProcessingContext implements Constants {
|
|||||||
}
|
}
|
||||||
Element argElement = typeUtils.asElement(argType);
|
Element argElement = typeUtils.asElement(argType);
|
||||||
if (isEntityOrEmbedded(argElement)) {
|
if (isEntityOrEmbedded(argElement)) {
|
||||||
result = createPropertyTypeAssoc(typeDef(argElement.asType()));
|
return createPropertyTypeAssoc(typeDef(argElement.asType()));
|
||||||
} else {
|
|
||||||
// look for targetEntity annotation attribute
|
|
||||||
final String targetEntity = readTargetEntity(field);
|
|
||||||
if (targetEntity != null) {
|
|
||||||
final TypeElement element = elementUtils.getTypeElement(targetEntity);
|
|
||||||
if (isEntityOrEmbedded(element)) {
|
|
||||||
result = createPropertyTypeAssoc(typeDef(element.asType()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (typeArguments.size() == 2) {
|
} else if (typeArguments.size() == 2) {
|
||||||
TypeMirror argType = typeArguments.get(1);
|
TypeMirror argType = typeArguments.get(1);
|
||||||
@@ -342,14 +340,10 @@ class ProcessingContext implements Constants {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result != null) {
|
if (typeInstanceOf(typeMirror, "java.lang.Comparable")) {
|
||||||
return result;
|
return new PropertyTypeScalarComparable(typeMirror.toString());
|
||||||
} else {
|
} else {
|
||||||
if (typeInstanceOf(typeMirror, "java.lang.Comparable")) {
|
return new PropertyTypeScalar(typeMirror.toString());
|
||||||
return new PropertyTypeScalarComparable(typeMirror.toString());
|
|
||||||
} else {
|
|
||||||
return new PropertyTypeScalar(typeMirror.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-9
@@ -286,6 +286,15 @@ class ProcessingContext implements Constants {
|
|||||||
return new PropertyTypeEnum(fullType, Split.shortName(fullType));
|
return new PropertyTypeEnum(fullType, Split.shortName(fullType));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// look for targetEntity annotation attribute
|
||||||
|
final String targetEntity = readTargetEntity(field);
|
||||||
|
if (targetEntity != null) {
|
||||||
|
final TypeElement element = elementUtils.getTypeElement(targetEntity);
|
||||||
|
if (isEntityOrEmbedded(element)) {
|
||||||
|
return createPropertyTypeAssoc(typeDef(element.asType()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isEntityOrEmbedded(fieldType)) {
|
if (isEntityOrEmbedded(fieldType)) {
|
||||||
// public QAssocContact<QCustomer> contacts;
|
// public QAssocContact<QCustomer> contacts;
|
||||||
return createPropertyTypeAssoc(typeDef(typeMirror));
|
return createPropertyTypeAssoc(typeDef(typeMirror));
|
||||||
@@ -331,15 +340,6 @@ class ProcessingContext implements Constants {
|
|||||||
Element argElement = typeUtils.asElement(typeArguments.get(0));
|
Element argElement = typeUtils.asElement(typeArguments.get(0));
|
||||||
if (isEntityOrEmbedded(argElement)) {
|
if (isEntityOrEmbedded(argElement)) {
|
||||||
return createPropertyTypeAssoc(typeDef(argElement.asType()));
|
return createPropertyTypeAssoc(typeDef(argElement.asType()));
|
||||||
} else {
|
|
||||||
// look for targetEntity annotation attribute
|
|
||||||
final String targetEntity = readTargetEntity(field);
|
|
||||||
if (targetEntity != null) {
|
|
||||||
final TypeElement element = elementUtils.getTypeElement(targetEntity);
|
|
||||||
if (isEntityOrEmbedded(element)) {
|
|
||||||
return createPropertyTypeAssoc(typeDef(element.asType()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (typeArguments.size() == 2) {
|
} else if (typeArguments.size() == 2) {
|
||||||
Element argElement = typeUtils.asElement(typeArguments.get(1));
|
Element argElement = typeUtils.asElement(typeArguments.get(1));
|
||||||
|
|||||||
Reference in new issue
Block a user