[JIRA] (HHH-16760) The multi-tenant filter does not work
by 周子杰 (JIRA)
周子杰 ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5fc7cba... ) *commented* on HHH-16760 ( https://hibernate.atlassian.net/browse/HHH-16760?atlOrigin=eyJpIjoiNzdjOW... )
Re: The multi-tenant filter does not work ( https://hibernate.atlassian.net/browse/HHH-16760?atlOrigin=eyJpIjoiNzdjOW... )
I'm late. Sorry!
@Marco Belladelli
as follow:
my entity
@Entity
public class Person {
@Id
private Long id;
private String name;
@TenantId
private String tenantId;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
my TenantIdentifierResolver
public class CurrentTenantIdentifierResolverImpl implements CurrentTenantIdentifierResolver{
private String currentTenant = "unknown";
public void setCurrentTenant(String currentTenant) {
this.currentTenant = currentTenant;
}
public String getCurrentTenant() {
return currentTenant;
}
@Override
public String resolveCurrentTenantIdentifier() {
return currentTenant;
}
@Override
public boolean validateExistingCurrentSessions() {
return true;
}
@Override
public boolean isRoot(String tenantId) {
return "-1".equals(tenantId);
}
}
Test cases
public class ORMStandaloneTestCase {
private EntityManagerFactory entityManagerFactory;
@BeforeEach
public void init() {
Configuration configuration = new Configuration()
.addAnnotatedClass(Person.class)
.setProperty(AvailableSettings.SHOW_SQL, "true")
.setProperty(AvailableSettings.HBM2DDL_AUTO, "update")
.setProperty(AvailableSettings.FORMAT_SQL, "true")
.setProperty(AvailableSettings.PASS, "ssss")
.setProperty(AvailableSettings.USER, "ssss")
.setProperty(AvailableSettings.DRIVER, "org.h2.Driver")
.setProperty(AvailableSettings.URL, "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
configuration.setCurrentTenantIdentifierResolver(new CurrentTenantIdentifierResolverImpl());
entityManagerFactory = configuration.buildSessionFactory();
}
@AfterEach
public void destroy() {
entityManagerFactory.close();
}
@Test
public void hhh123Test() {
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
// In 6.1.7 version , the sql statement log will print like this:
// select
// p1_0.id,
// p1_0.name,
// p1_0.tenantId
// from
// Person p1_0
// where
// p1_0.id=?
// and p1_0.tenantId = ?
// In 6.2.2 version (Or the 2.x version?), the sql statement log will print like this:
// select
// p1_0.id,
// p1_0.name,
// p1_0.tenantId
// from
// Person p1_0
// where
// p1_0.id=?
entityManager.find(Person.class,1L);
entityManager.getTransaction().commit();
entityManager.close();
}
}
Such behavior is not what I expect… Is it a bug or a feature?
( https://hibernate.atlassian.net/browse/HHH-16760#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16760#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100227- sha1:9e449c4 )
1 year, 2 months