mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-12 22:41:35 +00:00
#2153 - QueryBeans: OneToMany Map property is handled as PScalar instead of TQAssocBean
This commit is contained in:
1 parent
b3d439ed11
commit
ab9cdd8f5b
6 files changed
+71
-9
No files matched your search
@@ -1,8 +1,8 @@
|
|||||||
package org.example.domain;
|
package org.example.domain;
|
||||||
|
|
||||||
import io.ebean.Model;
|
import io.ebean.Model;
|
||||||
import io.ebean.annotation.CreatedTimestamp;
|
import io.ebean.annotation.WhenCreated;
|
||||||
import io.ebean.annotation.UpdatedTimestamp;
|
import io.ebean.annotation.WhenModified;
|
||||||
|
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.MappedSuperclass;
|
import javax.persistence.MappedSuperclass;
|
||||||
@@ -28,10 +28,10 @@ public abstract class BaseModel extends Model {
|
|||||||
@Version
|
@Version
|
||||||
Long version;
|
Long version;
|
||||||
|
|
||||||
@CreatedTimestamp
|
@WhenCreated
|
||||||
Timestamp whenCreated;
|
Timestamp whenCreated;
|
||||||
|
|
||||||
@UpdatedTimestamp
|
@WhenModified
|
||||||
Timestamp whenUpdated;
|
Timestamp whenUpdated;
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
|
|||||||
@@ -2,13 +2,10 @@ package org.example.domain;
|
|||||||
|
|
||||||
import io.ebean.annotation.DbArray;
|
import io.ebean.annotation.DbArray;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.*;
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.ManyToOne;
|
|
||||||
import javax.persistence.OneToMany;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contact entity bean.
|
* Contact entity bean.
|
||||||
@@ -38,6 +35,10 @@ public class Contact extends BaseModel {
|
|||||||
@OneToMany(mappedBy = "contact")
|
@OneToMany(mappedBy = "contact")
|
||||||
List<ContactNote> notes;
|
List<ContactNote> notes;
|
||||||
|
|
||||||
|
@OneToMany(cascade = CascadeType.PERSIST)
|
||||||
|
@MapKey(name="key")
|
||||||
|
Map<String,ContactOther> others;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package org.example.domain;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contact entity bean.
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name="be_contact_other")
|
||||||
|
public class ContactOther extends BaseModel {
|
||||||
|
|
||||||
|
String key;
|
||||||
|
|
||||||
|
int something;
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKey(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSomething() {
|
||||||
|
return something;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSomething(int something) {
|
||||||
|
this.something = something;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package org.querytest;
|
||||||
|
|
||||||
|
import org.example.domain.query.QContact;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class QContactTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_oneToManyMap() {
|
||||||
|
|
||||||
|
new QContact()
|
||||||
|
.others.fetch()
|
||||||
|
.findList();
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
@@ -330,6 +330,15 @@ class ProcessingContext implements Constants {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (typeArguments.size() == 2) {
|
||||||
|
TypeMirror argType = typeArguments.get(1);
|
||||||
|
if (argType.getKind() == TypeKind.WILDCARD) {
|
||||||
|
argType = ((WildcardType) argType).getExtendsBound();
|
||||||
|
}
|
||||||
|
Element argElement = typeUtils.asElement(argType);
|
||||||
|
if (isEntityOrEmbedded(argElement)) {
|
||||||
|
return createPropertyTypeAssoc(typeDef(argElement.asType()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -341,6 +341,11 @@ class ProcessingContext implements Constants {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (typeArguments.size() == 2) {
|
||||||
|
Element argElement = typeUtils.asElement(typeArguments.get(1));
|
||||||
|
if (isEntityOrEmbedded(argElement)) {
|
||||||
|
return createPropertyTypeAssoc(typeDef(argElement.asType()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user