Community
Participate
Working Groups
eclipseLink multitenancy bug: tenant id not added. I tried 2.5.1, 2.6.1 and 2.6.3. For example, Student and Course: ManyToMany. Student Course Student_Course ------- ------------------ ----------------- id, name id, name, tenantId studentId, courseId public class Student { @ManyToMany(...) List<Course> getCourses() { ... } } Course is multitenancy enabled, but Student is not. Search student left join course: The generated SQL: SELECT DISTINCT t1.ID AS a1, t1.NAME AS a2, t1.VERSION AS a3, t0.ID AS a4, t0.tenantId AS a5, t0.NAME AS a6, t0.VERSION AS a7 FROM Student t1 LEFT OUTER JOIN (Student_Course t2 JOIN Course t0 ON (t0.ID = t2.courseId)) ON (t2.studentId = t1.ID) ORDER BY t1.ID DESC The restriction for Course.tenantId is not added into the query. <entity class="Course" > <multitenant> <tenant-discriminator-column name="tenantId" context-property="tenant.id" discriminator-type="INTEGER"/> </multitenant> </entity> EntityManager em = .. em.setProperty("tenant.id", 1); CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder(); CriteriaQuery<Student> criteriaQuery = criteriaBuilder.createQuery(Student.class); Root<Student> root = criteriaQuery.from(Student.class); root.fetch("courses", JoinType.LEFT); criteriaQuery.distinct(true); TypedQuery<Student> query = em.createQuery(criteriaQuery); List<Student> students = query.getResultList(); The courses of a retrieved student will contain all the courses of the student from all tenants. But only the courses from tenant 1 is wanted.
I'm not sure this is a bug, though I would have expected some warnings or errors if not since the Multitenant Course entity should be treated as isolated, while I assume Student is shared as described here http://www.eclipse.org/eclipselink/documentation/2.4/concepts/cache001.htm What happens if you marked the Student as protected?
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink