how can i use multiple data source for a single application to separate company wise data

TanvirChowdhury :

say my entity models are as follows now

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Builder(builderClassName = "Builder", toBuilder = true)
@Entity
@Table(name = "clients")
public class Client extends Person {
    @Column(name = "initials")
    private String initials;

    @Column(name = "prefix")
    private String prefix;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_Id")
    private Company company;
}

all the records are stored in same table currently with a single datasource. But i want to change this. i want same database for every company and company specific data will be inserted to following company database. but the service and repository methods will be same.i want to achieve this in a way that my service and repository methods need not to be changed.

i have got few ideas from this link . https://blogs.sap.com/2016/12/19/developing-multi-tenant-applications-on-hcp-persistence-multitenancy-part-4/ . but i want some more sophisticated guideline about the implementation.

TanvirChowdhury :

finally using hibernate as ORM and using multi tenancy able to resolve this in mysql database. eclipse link does not support multi tenancy using mysql.they require Oracle Rack.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=83053&siteId=1