Bug 470580 - When using TablePerTenant multitenancy with entity inheritance descriptors are initialized in bad way
Summary: When using TablePerTenant multitenancy with entity inheritance descriptors ar...
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 critical with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard: multitenancy
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-19 07:07 EDT by Martin Frano CLA
Modified: 2022-06-09 10:29 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Frano CLA 2015-06-19 07:07:23 EDT
According to docs multi-tenant metadata can only be applied at the root level of the inheritance hierarchy when using a SINGLE_TABLE or JOINED inheritance strategy. This works when using non shared EMF (entity manager factory). But with shared EMF it doesn't work. In class org.eclipse.persistence.internal.sessions.DatabaseSessionImpl on lines 653-660 (ver. 2.6.0) in method initializeDescriptors are descriptors for entities with TablePerTenant multitenancy assigned to session in tablePerTenantDescriptors variable. Citation of comment in code:
"If the descriptor doesn't require initialization and has a table per tenant policy then add to the list to be cloned and initialized per client session."

Problem is that inherited multitenant child entities are not marked as multitenant and method descriptor.requiresInitialization(session) returns TRUE instead of FALSE for them. And they are not initialized right when tenant is set for EM (entity manager) after transaction start. Consequently it falls for child entities in post initialize phase when validating sequence number field because ObjectBuilder variable mappingsByField is not initialized and it s empty.

Exception:

Caused by: Exception [EclipseLink-41] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: A non-read-only mapping must be defined for the sequence number field.
Descriptor: RelationalDescriptor(sk.bantip.hotel.server.model.entity.crm.Company --> [DatabaseTable(crm_contact), DatabaseTable(crm_company)])
	at org.eclipse.persistence.exceptions.DescriptorException.mappingForSequenceNumberField(DescriptorException.java:931)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder.validate(ObjectBuilder.java:4438)
	at org.eclipse.persistence.descriptors.ClassDescriptor.selfValidationAfterInitialization(ClassDescriptor.java:4236)
	at org.eclipse.persistence.descriptors.ClassDescriptor.validateAfterInitialization(ClassDescriptor.java:6099)
	at org.eclipse.persistence.descriptors.ClassDescriptor.postInitialize(ClassDescriptor.java:3915)
	at org.eclipse.persistence.descriptors.ClassDescriptor.postInitialize(ClassDescriptor.java:3782)
	at org.eclipse.persistence.internal.sessions.AbstractSession.updateTablePerTenantDescriptors(AbstractSession.java:1454)
	at org.eclipse.persistence.internal.jpa.EntityManagerImpl.setProperty(EntityManagerImpl.java:2024)


Tried on Tomcat 7 and Glassfish 3.1.2.1.
Comment 1 Eclipse Webmaster CLA 2022-06-09 10:29:28 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink