Fix is to delay the extra join added via BeanPropertyAssocOne until after the children nodes have joined.

In this way the join is ONLY added if not already done so via a child node (SqlTreeNode).
This commit is contained in:
Rob Bygrave
2022-03-14 15:32:42 +13:00
parent 8e44ad71e8
commit c902caed24
4 changed files with 43 additions and 23 deletions
@@ -0,0 +1,2 @@
package io.ebeaninternal.server.query;public interface SqlTreeJoin {
}
@@ -18,20 +18,20 @@ public abstract class Access {
@Id
UUID id;
@ManyToOne
@DbForeignKey(noConstraint = true)
@JoinColumn(name = "accessor_id")
Customer accessor;
ACustomer accessor;
@ManyToOne
@DbForeignKey(noConstraint = true)
@JoinColumn(name = "principal_id")
Customer principal;
ACustomer principal;
@ManyToOne
@DbForeignKey(noConstraint = true)
@JoinColumn(name = "account_account_number")
@JoinColumn(name = "access_account_number")
Account account;
public UUID getId() {
@@ -42,22 +42,22 @@ public abstract class Access {
this.id = id;
}
public Customer getAccessor() {
public ACustomer getAccessor() {
return accessor;
}
public void setAccessor(Customer accessor) {
public void setAccessor(ACustomer accessor) {
this.accessor = accessor;
}
public Customer getPrincipal() {
public ACustomer getPrincipal() {
return principal;
}
public void setPrincipal(Customer principal) {
public void setPrincipal(ACustomer principal) {
this.principal = principal;
}
public Account getAccount() {
return account;
}
@@ -66,5 +66,5 @@ public abstract class Access {
this.account = account;
setPrincipal(account.getOwner());
}
}
}
@@ -1,9 +1,6 @@
package org.tests.model.join;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.ManyToOne;
import javax.persistence.*;
import org.tests.model.basic.Customer;
@@ -13,9 +10,10 @@ public abstract class Account {
@Id
String accountNumber;
@ManyToOne
Customer owner;
@JoinColumn(name = "owner_id")//, referencedColumnName = "id")
ACustomer owner;
public String getAccountNumber() {
return accountNumber;
@@ -25,12 +23,12 @@ public abstract class Account {
this.accountNumber = accountNumber;
}
public Customer getOwner() {
public ACustomer getOwner() {
return owner;
}
public void setOwner(Customer owner) {
public void setOwner(ACustomer owner) {
this.owner = owner;
}
}
}
@@ -0,0 +1,20 @@
package org.tests.model.join;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class ACustomer {
@Id
final String cid;
final String name;
String status = "A";
public ACustomer(String cid, String name) {
this.cid = cid;
this.name = name;
}
}