我正在尝试设置一个多租户Web应用程序,同时具有(理想情况下)数据库分离和模式分离方法的可能性.虽然我将从Schema分离开始.我们目前正在使用:
大部分时间我都遵循这个主题(因为解决方案@Transactional).但我在执行方面有点迷失MultiTenantContextConnectionProvider.在这里也提到了类似的问题,但有些方面我无法弄清楚:
1)连接池会发生什么?我的意思是,它是由Spring还是Hibernate管理的?我猜ConnectionProviderBuilder- 或者按照建议 - 任何实现,Hibernate都是管理它的人.
2)Spring不管理连接池是一种好方法吗?或者Spring是否可以管理它?
3)这是未来实现数据库和模式分离的正确途径吗?
任何评论或描述都完全赞赏.
应用程序的context.xml
<beans>
...
<bean id="dataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
<property name="targetDataSource" ref="c3p0DataSource" />
</bean>
<bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="org.postgresql.Driver" />
... other C3P0 related config
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="packagesToScan" value="com.webapp.domain.model" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.default_schema">public</prop>
<prop key="hibernate.multiTenancy">SCHEMA</prop>
<prop key="hibernate.tenant_identifier_resolver">com.webapp.persistence.utility.CurrentTenantContextIdentifierResolver</prop>
<prop key="hibernate.multi_tenant_connection_provider">com.webapp.persistence.utility.MultiTenantContextConnectionProvider</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="autodetectDataSource" …Run Code Online (Sandbox Code Playgroud) 我使用EJB 3.0和Hibernate 4和PostgreSQL作为我的数据库服务器来创建多租户系统,其中每个租户将具有单独但相同的架构.我仍然在这里我有3种方案的试验阶段public,company1,company2都具有单个表的人.现在我要做的是根据用户在运行时更改模式,以便他只能查看他/她公司的数据.
这是我的示例代码:实体对象:
package com.neebal.domain;
import java.io.Serializable;
import java.lang.Long;
import java.lang.String;
import javax.persistence.*;
import org.eclipse.persistence.annotations.Multitenant;
import org.eclipse.persistence.annotations.MultitenantType;
@Entity
//@Table(schema = "company1")
public class Person implements Serializable {
@Id
private Long id;
private String name;
private static final long serialVersionUID = 1L;
public Person() {
super();
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void …Run Code Online (Sandbox Code Playgroud)