1

ホテルが提供するすべてのサービスを保持するテーブル Services と 1 対多の関係にある Hotels を保持するテーブルがあります。これらのサービスは複数の言語で利用できる必要があるため、サービスごとに X 言語の X エントリが存在します。

-----------             --------------------            --------------------
| Hotel   |             | Services         |            | ServicesLocale   |
-----------             |-------------------            |-------------------
| hotelId |-------------| serviceId        |------------| serviceLocaleId  |
| name    |             | category         |            | locale           |
| ...     |             | hotelId          |            | description      |
-----------             | ...              |            | serviceId        |
                        --------------------            --------------------

Hibernate と Spring MVC を使用して、Web アプリケーションでこの情報を管理しています。現在、ServicesLocale データを (String locale, ServicesLocale) の HashMap として Services にマップしており、Service を取得するときに常にすべてのロケール情報を取得しています。しかし、ホテルのすべてのサービスを特定のロケールごとの説明で並べ替えてリストする必要があるため、これは期待どおりには機能しません。

したがって、最初の解決策は、特定のロケールのサービス オブジェクトのみを取得することでした。これにより、ハッシュマップ マッピングが役に立たなくなります (オブジェクトを取得するだけなので)。

特定のロケールのみをドメイン オブジェクトにマップするベスト プラクティスは何ですか?

注:普遍的な解決策が望まれますが、私は読み取り専用操作のみを実行しています

編集: いくつかのコードを投稿します。

ホテル:

public class HotelVO extends BaseModel implements java.io.Serializable {


    private Long hotelId;
    private String hotel;
    private String address;
    private String code;
    private String latitude;
    private String longitude;

    private Set servicesVOs = new HashSet(0);
}

マッピング:

<hibernate-mapping>
    <class catalog="bdd" name="HotelVO" table="hotels">
        <id name="hotelId" type="java.lang.Long">
            <column name="hotelId" precision="4" scale="0" />
            <generator class="assigned" />
        </id>


        <property generated="never" lazy="false" name="hotel" type="java.lang.String">
            <column name="hotel" not-null="true" />
        </property>

        <property generated="never" lazy="false" name="address" type="java.lang.String">
            <column name="address" />
        </property>

        <property generated="never" lazy="false" name="code" type="java.lang.String">
            <column length="10" name="code" />
        </property>

        <property generated="never" lazy="false" name="latitude" type="java.lang.String">
            <column name="latitud" />
        </property>
        <property generated="never" lazy="false" name="longitude" type="java.lang.String">
            <column name="longitud" />
        </property>


        <set fetch="select" inverse="true" lazy="true" name="servicesVOs" sort="unsorted" table="servicios">
            <key>
                <column name="hotelId" not-null="true" />
            </key>
            <one-to-many class="ServiceVO" />
        </set>
    </class>
</hibernate-mapping>

サービス:

public class ServiceVO extends BaseModel implements java.io.Serializable {

    private Long serviceId;
    private CategoryVO categoryVO;
    private HotelVO hotelVO;
    private Long coordX;
    private Long coordY;
    private Long floor;
    private Map servicesLocaleVOs = new HashMap(0);

}

マッピング:

<hibernate-mapping>
    <class catalog="bdd" name="ServiceVO" table="services">
        <id name="serviceId" type="int">
            <column name="serviceId" />
            <generator class="assigned" />
        </id>

        <many-to-one class="CategoryVO" fetch="join" name="categoryVO">
            <column name="categoryId" not-null="true" />
        </many-to-one>

        <many-to-one class="HotelVO" fetch="select" name="hotelVO">
            <column name="hotelId" not-null="true" />
        </many-to-one>
        <property generated="never" lazy="false" name="coordX" type="java.lang.Long">
            <column name="coord_x" precision="20" scale="0" />
        </property>
        <property generated="never" lazy="false" name="coordY" type="java.lang.Long">
            <column name="coord_y" precision="20" scale="0" />
        </property>

        <property generated="never" lazy="false" name="floor" type="java.lang.Long">
            <column name="floor" precision="3" scale="0" />
        </property>

        <map fetch="select" inverse="true" lazy="true" name="servicesLocaleVOs" sort="unsorted" table="serviceslocale">
            <key>
                <column name="serviceId" />
            </key>
            <index column="locale" type="java.lang.String" />
            <one-to-many class="LocaleServiceVO" />
        </map>
    </class>
</hibernate-mapping>

ロケール サービス:

public class LocaleServiceVO  extends BaseModel implements java.io.Serializable {

    private Long localeServiceId;
    private String locale;
    private ServiceVO serviceVO;
    private String name;
    private String description;
}

マッピング:

<hibernate-mapping>
    <class catalog="bdd" name="LocaleServiceVO" table="serviceslocale">
        <id name="localeServiceId" type="int">
            <column name="localeServiceId" />
            <generator class="assigned" />
        </id>

                <property generated="never" lazy="false" name="locale" type="java.lang.String">
            <column name="locale" />
        </property>

        <many-to-one class="ServiceVO" fetch="select" name="serviceVO">
            <column name="serviceId" />
        </many-to-one>

        <property generated="never" lazy="false" name="name" type="java.lang.String">
            <column name="name" />
        </property>

        <property generated="never" lazy="false" name="description" type="java.lang.String">
            <column length="65535" name="description" />
        </property>

    </class>
</hibernate-mapping>
4

0 に答える 0