Hi,
i want to user the Hibernate Filter feature to separate the data of different tenants.
Therefor i created a base class TenantEntity.
Code:
@FilterDef(name = "tenantFilter",
defaultCondition = "_tenantId = :tenantId",
parameters = @ParamDef(name = "tenantId", type = "long"))
@Filter(name = "tenantFilter")
@MappedSuperclass
public class TenantEntity extends BaseEntity {
...
private Tenant tenant;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "_tenantId")
public Tenant getTenant() {
return tenant;
}
}
The problem is that for some mappings i get an "
Column '_tenantId' in where clause is ambiguous" error
For example for the following code where the class TemplateConfiguration has a
one to many association with the class TemplatePage.
Code:
@Entity
@Table(name = "templateconfigurations")
public class TemplateConfiguration extends TenantEntity {
...
private List<TemplatePage> pages = new ArrayList<TemplatePage>();
@OneToMany(mappedBy = "configuration", fetch = FetchType.EAGER)
@Cascade(CascadeType.ALL)
public List<TemplatePage> getPages() {
return pages;
}
}
Code:
@Entity
@Table(name = "templatepages")
public class TemplatePage extends TenantEntity {
...
private TemplateConfiguration configuration;
@ManyToOne
@JoinColumn(name = "_configurationId")
public TemplateConfiguration getConfiguration() {
return configuration;
}
}
In this case it would not be possible to use another superclass for the TemplatePage without
any tenant informations. Because i also want to query the TemplatePage's.
Another simple is a class LogEntry that has a recursive one to many association:
Code:
@Entity
@Table(name = "logentries")
public class LogEntry extends TenantEntity {
...
private List<LogEntry> childEntries = new ArrayList<LogEntry>();
@OneToMany(mappedBy = "parentEntry")
@Cascade(CascadeType.ALL)
public List<LogEntry> getChildEntries() {
return childEntries;
}
}