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
+78
-16
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;
|
||||||
@@ -11,10 +11,10 @@ import java.sql.Timestamp;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Base domain object with Id, version, whenCreated and whenUpdated.
|
* Base domain object with Id, version, whenCreated and whenUpdated.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* Extending Model to enable the 'active record' style.
|
* Extending Model to enable the 'active record' style.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* whenCreated and whenUpdated are generally useful for maintaining external search services (like
|
* whenCreated and whenUpdated are generally useful for maintaining external search services (like
|
||||||
* elasticsearch) and audit.
|
* elasticsearch) and audit.
|
||||||
@@ -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.
|
||||||
@@ -22,28 +19,32 @@ public class Contact extends BaseModel {
|
|||||||
|
|
||||||
@Column(length=50)
|
@Column(length=50)
|
||||||
String firstName;
|
String firstName;
|
||||||
|
|
||||||
@Column(length=50)
|
@Column(length=50)
|
||||||
String lastName;
|
String lastName;
|
||||||
|
|
||||||
@Column(length=200)
|
@Column(length=200)
|
||||||
String email;
|
String email;
|
||||||
|
|
||||||
@Column(length=20)
|
@Column(length=20)
|
||||||
String phone;
|
String phone;
|
||||||
|
|
||||||
@ManyToOne(optional=false)
|
@ManyToOne(optional=false)
|
||||||
Customer customer;
|
Customer customer;
|
||||||
|
|
||||||
@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.
|
||||||
*/
|
*/
|
||||||
public Contact() {
|
public Contact() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct with a firstName and lastName.
|
* Construct with a firstName and lastName.
|
||||||
*/
|
*/
|
||||||
@@ -51,7 +52,7 @@ public class Contact extends BaseModel {
|
|||||||
this.firstName = firstName;
|
this.firstName = firstName;
|
||||||
this.lastName = lastName;
|
this.lastName = lastName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFirstName() {
|
public String getFirstName() {
|
||||||
return firstName;
|
return firstName;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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