Documentation Home

MultiTenant Enabling Custom Data

Your custom implementation is likely to introduce new tables and entities that are tenant specific. Broadleaf uses
annotations to access the MultiTenant behavior.

For classes (like Customer and Order) that are site specific, just add the following annotation before your public class
statement in your java file.

@DirectCopyTransform({
    @DirectCopyTransformMember(templateTokens = DirectCopyTransformTypes.MULTITENANT_SITE)
})

For classes that are Catalog specific (like extensions to Product, Offer, etc.), add the following annotations:

@DirectCopyTransform({
    @DirectCopyTransformMember(templateTokens = DirectCopyTransformTypes.MULTITENANT_CATALOG)
})

When to add a discriminator

Note: When in doubt, it is better to err on the side of adding the discriminator.

  1. Mark an entity for discrimination using the @DirectCopyTransform and @DirectCopyTransformMember annotations
    (see CategoryImpl)

  2. Mark a property for discrimination using the @SiteDiscriminatable annotation. Please note, muti-tenant filtered collections are NOT eligible for level 2 cache, which results in a query to the database every time the collection is lazy initialized. This can result in production performance degradation depending on how frequently the collection is utilized. It is for this reason that we recommend utilizing a custom service or service extension that explicitly creates a query for the collection entity members based on the parent entity. As long as the collection member class has included the DirectCopyTransform annotation for multitenancy, the multitenant discrimination will be automatically included for you in your query and your query will be eligible for level 2 cache. Here's an example HQL query that would retrieve all the featured products for a category:

    1. SELECT featuredProduct FROM org.broadleafcommerce.core.catalog.domain.FeaturedProduct featuredProduct WHERE featuredProduct.category.id = :categoryId
  3. In ManyToMany relationships where one side includes @DirectCopyTransform, the other side should get a @DirectCopyTransform annotation as well

    1. If the relationship property is being accessed via API, it should be configured to have a @SiteDiscriminatable annotation as well (please see the recommendation above regarding @SiteDiscriminatable).
  4. If a join table is modeled in the domain, or an adorned target entity is employed, and either of the ManyToOne refs from the entity are discriminatable (i.e. use the @DirectCopyTransform annotation), then that entity should get @DirectCopyTransform as well.

  5. If an entity should be able to be viewed via direct reference in the admin (e.g.
    http://site1.localhost.com:8080/admin/org.broadleafcommerce.core.catalog.domain.Sku/2), then that entity should
    get @DirectCopyTransform.

  6. For entity trees where the top node is discriminatable, and all the branches and leaves of the tree related
    back to the root (e.g. Order is related to OrderItems, FulfillmentGroupItems, etc...), then the branches
    in the tree should get @DirectCopyTransform as well.

    1. For example, OrderItemImpl would get @DirectCopyTransform since it contains other viewable collections inside of it, like order item adjustments. It is therefore a branch node.
    2. For example, OrderAdjustmentImpl would not get @DirectCopyTransform, since this entity does not itself contain any viewable collections. It is therefore a leaf node.