Hi: I have see any demo for the multiTenant of mutiple database. But can't solve my problem because I have only single database and all tables have tencent column to choose it. I had see hibernate 5 supported MultiTenancyStrategy#DISCRIMINATOR but i don't see any demo or code to show it? `AbstractDataSourceBasedMultiTenantConnectionProviderImpl` is used to choose database. but i want to use a column like it. I had use filter to appove it. but i think it's not a correct solution. The base entity like this. the orgRrn is my tencent identifier. ```java package com.newbiest.base.model; ---- import com.newbiest.base.ui.model.*; import com.newbiest.base.utils.StringUtils; import com.newbiest.base.utils.ThreadLocalContext; import com.newbiest.security.model.NBAuthority; import com.newbiest.security.model.NBOrg; import com.newbiest.security.model.NBUser; import lombok.*; import lombok.experimental.Accessors; import org.hibernate.annotations.FilterDef; import org.hibernate.annotations.ParamDef; import org.hibernate.annotations.Where;
import javax.persistence.*; import java.io.Serializable;
/**
* 所有的POJO基类 * Created by guoxunbo on 2017/9/7. */ @MappedSuperclass @Accessors(chain = true) @NoArgsConstructor @ToString //@Where(clause=NBBase.SQL_AVAILABLE_OBJ_CONDITION) 当前的@where无效。无法应用到子类。需要每个类都定义。计划在hibernate6.X上实现 //@FilterDef(name = "multi-tenant", parameters = @ParamDef(name = "orgRrn", type = "long")) public class NBBase implements Serializable, Cloneable \{
private static final long serialVersionUID = -4455314847475119658L;
public static final String AVAILABLE_OBJ_CONDITION = " activeFlag = 'Y'"; public static final String SQL_AVAILABLE_OBJ_CONDITION = " ACTIVE_FLAG = 'Y'";
public static final String ORG_CONDITION = " (orgRrn = :orgRrn OR orgRrn = 0)";
// public static final String SQL_BASE_CONDITION = " ACTIVE_FLAG = 'Y' AND (ORG_RRN = :orgRrn OR ORG_RRN = 0) ";
public static final String LANGUAGE_CHINESE = "Chinese"; public static final String LANGUAGE_ENGLISH = "English";
@Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name="OBJECT_RRN") @Setter @Getter protected Long objectRrn;
@Column(name="ORG_RRN") @Getter protected Long orgRrn = 0L;
@Column(name="ACTIVE_FLAG") @Setter @Getter protected String activeFlag = StringUtils.YES;
public Boolean getActiveFlag() \{ return StringUtils.YES.equalsIgnoreCase(activeFlag); }
public void setActiveFlag(Boolean activeFlag) \{ this.activeFlag = activeFlag ? StringUtils.YES : StringUtils.NO; }
} ``` Thank you |
|