アプリケーションのインスタンスごとに固有の名前を持つテーブルを持ってしようとしています

Kirderf:

データベースへの新しいです。私は、アプリケーションの各インスタンスは独自のデータベースを持ちたい問題を持ちます。ORMの現在の設定でこれを実装する方法を把握しよう。現在のjavaxの永続性を使用しました。誰もがこれに対する解決策を持っていますか?

SIMPLE:各テーブルに一意の名前を持っていたいです

    //thread safe
    private EntityManagerFactory emf;
    public ImageDAOManager(EntityManagerFactory emf) {
        this.emf = emf;
    }
....

@Entity
public class ImageDAO implements Serializable {
    @Id
    private String path;
    private int fileSize;
    private long date;
    private int imageHeight;
    private int imageWidth;
    private double latitude;
    private double longitude;
    private String tags;

    public ImageDAO(String path, int fileSize, long date, int imageHeight, int imageWidth, double latitude, double longitude) {
        this.path = path;
        this.fileSize = fileSize;
        this.date = date;
        this.imageHeight = imageHeight;
        this.imageWidth = imageWidth;
        this.latitude = latitude;
        this.longitude = longitude;
        this.tags = "";
    }
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence"
             version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">

    <persistence-unit name="LecturePU" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <class>backend.database.ImageDAO</class>
        <properties>
            <!--username and password is temporarily here-->
            <property name="javax.persistence.jdbc.url" value="" />
            <property name="javax.persistence.jdbc.user" value="" />
            <property name="javax.persistence.jdbc.password" value="" />
            <!-- EclipseLink should create the database schema automatically -->
            <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
            <property name="eclipselink.ddl-generation.output-mode" value="database" />
        </properties>
    </persistence-unit>
</persistence>```
Janáčミーナ:

あなたのアプリのインスタンスごとに新しいデータベースを持つことは確かに適切なソリューションではありません。代わりに、あなたは私がこの記事を示唆し、マルチテナントアプリケーションになります。https://dzone.com/articles/multi-tenancy-using-jpa-spring-and-hibernate-part

要約すると、アプリケーションのインスタンスごとに新しいデータベースが厳しく、履歴照会を実行するための機能をあなたのパフォーマンスが低下します、そして潜在的に同時実行を発行します。

クイックフィックスは、次のような列を持っているだろうtenant_idか、だけでも、instance_idあなたがそのデータをそのインスタンスのみのために照会されていることを確認に役立つと思われます。

おすすめ

転載: http://10.200.1.11:23101/article/api/json?id=378816&siteId=1