Bug 488599 - @ManyToMany generates invalid query with multitenant
Summary: @ManyToMany generates invalid query with multitenant
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows NT
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-26 17:35 EST by Christopher Hunter-Jonson CLA
Modified: 2022-06-09 10:06 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christopher Hunter-Jonson CLA 2016-02-26 17:35:12 EST
Named Query for ManyToMany generates incorrect referencing column by table name instead of alias:

ptnr01.DTYPE should be t0.DTYPE

SELECT DISTINCT ptnr01.DTYPE FROM ptnr04 t0, ptnr01 t1 WHERE (((t0.ptnr_role_id = ?) AND (t1.tenant_id = ?)) AND (t0.tenant_id = ?)




Application is JPA in Glassfish using PostGresql as the database.

Multitenant is single table:

@Multitenant(SINGLE_TABLE)
@TenantDiscriminatorColumn(name="tenant_id",discriminatorType=STRING,length=50,contextProperty="tenantId")

Definition of ManyToMany

owning side
@Table(name="ptnr01")
public class PartnerBase implements Serializable {
..
@ManyToMany
 @JoinTable(name="ptnr06",
   joinColumns=@JoinColumn(name="partner_id"),
   inverseJoinColumns=@JoinColumn(name="ptnr_role_id"))
 private List<PartnerRole> roles;   
..
}

dependant side
@Multitenant(SINGLE_TABLE)
@TenantDiscriminatorColumn(name="tenant_id",discriminatorType=STRING,length=50,contextProperty="tenantId")
@Table(name="ptnr04")
public class PartnerRole implements Serializable {
..
@ManyToMany(mappedBy = "roles")
 private List<PartnerBase> partners;

..
}

named query:
@NamedQuery(name = "partnersByRole",query ="select p from PartnerBase p join PartnerRole r  where r.ptnrRoleId = :roleId ")

SQL generated:
SELECT DISTINCT ptnr01.DTYPE FROM ptnr04 t0, ptnr01 t1 WHERE (((t0.ptnr_role_id = ?) AND (t1.tenant_id = ?)) AND (t0.tenant_id = ?)
Comment 1 Eclipse Webmaster CLA 2022-06-09 10:06:16 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink