Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 356408 - MULTITENANT_PROPERTY_DEFAULT - persistence unit property or just a default string?
Summary: MULTITENANT_PROPERTY_DEFAULT - persistence unit property or just a default st...
Status: CLOSED INVALID
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-31 16:53 EDT by Karen Butzke CLA
Modified: 2022-06-09 10:19 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Karen Butzke CLA 2011-08-31 16:53:14 EDT
In PersistenceUnitProperties the following property is defined. The javadoc makes it sound like it is to be used as a persistence unit property to define the default contextProperty for tenant discriminator columns. It is not being used, but instead is purely a default String as the NOTE in the javadoc seems to state. I am not sure if this is a bug or if the javadoc just needs to be cleaned up or maybe this String doesn't even belong in PersistenceUnitProperties. This property also exists in EntityManagerProperties where it is not processed. 

/**
 * The <code>"eclipselink.tenant-id"</code> property specifies the 
 * default context property used to populate multitenant entities.
 * 
 * NOTE: This is merely a default multitenant property than can be used on 
 * its own or with other properties defined by the user. Users are not 
 * obligated to use this property and are free to specify their own.
 * 
 * @see org.eclipse.persistence.annotations.Multitenant
 * @see org.eclipse.persistence.annotations.TenantDiscriminatorColumn
 * 
 * Example: persistence.xml file <code>
 * <property name="eclipselink.tenant-id" value="Oracle"/>
 * </code> Example: property Map <code>
 * propertiesMap.put(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, "Oracle");
 * </code>
 */
public static final String MULTITENANT_PROPERTY_DEFAULT = "eclipselink.tenant-id";
Comment 1 Guy Pelletier CLA 2011-09-01 09:19:32 EDT
I'm confused, it's the default context property for multitenant that can be set at the PU or EM level. This property needs to be set if any Entity uses a defaulted TenantDiscriminatorColumn since 'eclipselink.tenant-id' is the default context property. There is no metadata processing per say of this property.

Context properties must be populated from the user (on the PU or EM) otherwise they will get an exception when executing their queries.
Comment 2 Karen Butzke CLA 2011-09-01 09:36:20 EDT
I must be confused as well :)
In TenantDiscriminatorColumnMetadata.process(MetadataDescriptor) it sets the m_contextProperty to MULTITENANT_PROPERTY_DEFAULT if it is null. This would make the m_contextProperty be "eclipselink.tenant-id". Given the example in the javadocs I would expect the m_contextProperty should get set to "Oracle". Is this the expected behavior? I don't see how that could be happening when nothing ever calls EntityManagerFactoryProvider.getConfigPropertyAsString for this property.
Comment 3 Guy Pelletier CLA 2011-09-01 09:52:11 EDT
No, so the value 'Oracle' needs to be set by the user in the PU definition or on an EM.

E.G.

em.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT,
"Oracle");

or 

<property name="eclipselink.tenant-id" value="Oracle"/>

Another example, if the user had specified something like this:

@Entity
@Multitenant
@TenantDiscriminatorColumn(name="TENANT_ID", contextProperty="tenant-id")

Then you would see (set by the user):

em.setProperty("tenant-id", "Oracle")

or in XML

<property name="tenant-id" value="Oracle"/>

So metadata processing does not process and set the value of the context property, only the name of the context property it needs to look up on the session at runtime. 

Using the example above it says we have a multitenant column named TENANT_ID. When we insert the multitenant entity we need to populate that column with a value. The context property tells us which property to look for on the session. If the user doesn't set it (through the EM or PU), they will get an exception.
Comment 4 Karen Butzke CLA 2011-09-02 12:10:13 EDT
Thanks for the explanation Guy, I think I finally get it! So Dali could have a validation error if a particular contextProperty does not have a corresponding property defined in the persistence.xml. Of course that doesn't take into account them setting the property on the entityManager in code.
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:19:48 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink