Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] ManyToMany multitenant entities with regular entities

The design doc here:
http://wiki.eclipse.org/EclipseLink/DesignDocs/Multi-Tenancy/TablePerTenant
has the following left as a future item:
"Allow for relationships from non table per tenant entities to table per tenant entities"

So I suspect that relationships are supported, but only from table per tenant to shared entities, not the other way around.

Try removing the ManyToMany back relationship within User. You will need to manually query over all entityManagers/tenants to get all awards associated with a particular user anyway.

Looking over caching isolation described here:
http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Caching/Shared_and_Isolated
you might try making the User cache type protected. If it works, the User awards collection might be populated with the current tenants awards.

Best Regards,
Chris

On 19/10/2012 4:11 PM, Guy Pelletier wrote:
Erik,

When you say startup, do you mean at Entity Manager creation time? When
do you set the tenant context?

Can you provide the full stack trace?

Out of curiosity, do you get past the error if User is set to be
multitenant as well?

Thanks,
Guy

On 19/10/2012 3:29 PM, Erik Froese wrote:
Hey,

I have a question about relationships between ManyToMany fields
between two Entities. One is a MultiTenant Entity (one table per
tentant) and the other is an Entity that should span all tenants.

In this application we'll need to have Users that can switch between
multiple tenants. Think of it like being on github.com when you
"switch" organizations. So the User entity in this app should be just
a normal JPA entity.

The second entity is Award. Awards will have a Set<User>  of
investigators. In order to look up that list I'd like to be able to
call theAward.getInvestigators() and get a set of User objects.

I understand that querying the Awards a User is an investigator of is
more complicated. It probably means opening up an EM for each of the
user's tenancies and appending the Sets of awards together.

I'm getting the following error on startup:

Exception [EclipseLink-0] (Eclipse Persistence Services -
2.4.0.v20120608-r11652):
org.eclipse.persistence.exceptions.IntegrityException|Descriptor
Exceptions: |---------------------------------------------------------||Exception
[EclipseLink-53] (Eclipse Persistence Services -
2.4.0.v20120608-r11652):
org.eclipse.persistence.exceptions.DescriptorException|Exception
Description: The relation table name is not set for this
mapping.|Mapping:
org.eclipse.persistence.mappings.ManyToManyMapping[awards]|Descriptor:
RelationalDescriptor(com.rsmart.rfabric.model.User -->
[DatabaseTable(USER)])||Runtime Exceptions:

What table name should I be specifying? I think thee should be join
table per tenant no?

Code snippets below for the models.

Thanks
Erik

@Entity
public class User extends BaseEntity implements Serializable {

...

    private Set<Award>  awards;
    @ManyToMany(mappedBy="investigators")

    public Set<Award>  getAwards() {
      return awards;
    }

    public void setAwards(Set<Award>  awards) {
      this.awards = awards;
    }
}

And Award

@Entity
@Multitenant(MultitenantType.TABLE_PER_TENANT)
public class Award extends BaseEntity {

   ...

   Set<User>  investigators;

   @ManyToMany
   public Set<User>  getInvestigators() {
     return investigators;
   }

   public void setInvestigators(Set<User>  investigators) {
     this.investigators = investigators;
   }
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

--

Oracle <http://www.oracle.com>
Guy Pelletier

ORACLE Canada, 45 O'Connor Street Suite 400 Ottawa, Ontario Canada K1P 1A4
Green Oracle <http://www.oracle.com/commitment> Oracle is committed to
developing practices and products that help protect the environment



_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top