2010-12-21 2 views
0

私はPOJOと特定のレースのポイントシステムを指定する整数を保持する休止状態(1位= 100、2位= 70 ......)を持っていて、配列オブジェクトを作成し、hbmファイルとpojoクラスにマップします。ここHibernate配列?

は、それが現時点でどのように見えるかです:あなたはそのハック仕事を見ることができると私は使用することができるかどうかを知りたいと

package com.jr.model; 

public class RaceSeriesPointsRules { 

    private String id; 

    private int pos1; 
    private int pos2; 
    private int pos3; 
    private int pos4; 
    private int pos5; 
    private int pos6; 
    private int pos7; 
    private int pos8; 
    private int pos9; 
    private int pos10; 
    private int pos11; 
    private int pos12; 
    private int pos13; 
    private int pos14; 
    private int pos15; 
    private int pos16; 



    public RaceSeriesPointsRules(int pos1, int pos2, int pos3, int pos4, 
      int pos5, int pos6, int pos7, int pos8, int pos9, int pos10, 
      int pos11, int pos12, int pos13, int pos14, int pos15, int pos16) { 

     this.pos1 = pos1; 
     this.pos2 = pos2; 
     this.pos3 = pos3; 
     this.pos4 = pos4; 
     this.pos5 = pos5; 
     this.pos6 = pos6; 
     this.pos7 = pos7; 
     this.pos8 = pos8; 
     this.pos9 = pos9; 
     this.pos10 = pos10; 
     this.pos11 = pos11; 
     this.pos12 = pos12; 
     this.pos13 = pos13; 
     this.pos14 = pos14; 
     this.pos15 = pos15; 
     this.pos16 = pos16; 
    } 

    public RaceSeriesPointsRules(){ 

    } 

    public String getId() { 
     return id; 
    } 
    public void setId(String id) { 
     this.id = id; 
    } 
    public int getPos1() { 
     return pos1; 
    } 
    public void setPos1(int pos1) { 
     this.pos1 = pos1; 
    } 
    public int getPos2() { 
     return pos2; 
    } 
    public void setPos2(int pos2) { 
     this.pos2 = pos2; 
    } 
    public int getPos3() { 
     return pos3; 
    } 
    public void setPos3(int pos3) { 
     this.pos3 = pos3; 
    } 
    public int getPos4() { 
     return pos4; 
    } 
    public void setPos4(int pos4) { 
     this.pos4 = pos4; 
    } 
    public int getPos5() { 
     return pos5; 
    } 
    public void setPos5(int pos5) { 
     this.pos5 = pos5; 
    } 
    public int getPos6() { 
     return pos6; 
    } 
    public void setPos6(int pos6) { 
     this.pos6 = pos6; 
    } 
    public int getPos7() { 
     return pos7; 
    } 
    public void setPos7(int pos7) { 
     this.pos7 = pos7; 
    } 
    public int getPos8() { 
     return pos8; 
    } 
    public void setPos8(int pos8) { 
     this.pos8 = pos8; 
    } 
    public int getPos9() { 
     return pos9; 
    } 
    public void setPos9(int pos9) { 
     this.pos9 = pos9; 
    } 
    public int getPos10() { 
     return pos10; 
    } 
    public void setPos10(int pos10) { 
     this.pos10 = pos10; 
    } 
    public int getPos11() { 
     return pos11; 
    } 
    public void setPos11(int pos11) { 
     this.pos11 = pos11; 
    } 
    public int getPos12() { 
     return pos12; 
    } 
    public void setPos12(int pos12) { 
     this.pos12 = pos12; 
    } 
    public int getPos13() { 
     return pos13; 
    } 
    public void setPos13(int pos13) { 
     this.pos13 = pos13; 
    } 
    public int getPos14() { 
     return pos14; 
    } 
    public void setPos14(int pos14) { 
     this.pos14 = pos14; 
    } 
    public int getPos15() { 
     return pos15; 
    } 
    public void setPos15(int pos15) { 
     this.pos15 = pos15; 
    } 
    public int getPos16() { 
     return pos16; 
    } 
    public void setPos16(int pos16) { 
     this.pos16 = pos16; 
    } 



} 

:ここ

<?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
            "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 

<hibernate-mapping> 
    <class name="com.jr.model.RaceSeriesPointsRules" table="RACE_SERIES_POINTS_RULES"> 
     <id name="id" type="string"> 
      <column name="ID" /> 
      <generator class="uuid" /> 
     </id> 



     <property name="pos1" type="integer" column="POS1" /> 
     <property name="pos2" type="integer" column="POS2" /> 
     <property name="pos3" type="integer" column="POS3" /> 
     <property name="pos4" type="integer" column="POS54" /> 
     <property name="pos5" type="integer" column="POS5" /> 

     <property name="pos6" type="integer" column="POS6" /> 
     <property name="pos7" type="integer" column="POS7" /> 
     <property name="pos8" type="integer" column="POS8" /> 
     <property name="pos9" type="integer" column="POS9" /> 

     <property name="pos10" type="integer" column="POS10" /> 
     <property name="pos11" type="integer" column="POS11" /> 
     <property name="pos12" type="integer" column="POS12" /> 
     <property name="pos13" type="integer" column="POS13" /> 

     <property name="pos14" type="integer" column="POS14" /> 
     <property name="pos15" type="integer" column="POS15" /> 
     <property name="pos16" type="integer" column="POS16" /> 

    </class> 

</hibernate-mapping> 

は、以下の私のPOJOでありますarray.sizeの列を作成し、それらをintで埋め込むためにhibernate内の配列これは私のpojoを非常に小さくし、彼らが終わった位置に基づいてレーサーが蓄積したptsを計算する際に論理をします:

レーサーAは第2位、レーサーは位置= 2、

race_series_points_rulesどこから

選択column.pos2 .........

編集:別の質問は、レースシリーズAのみが10位とレースシリーズBは16を持っているを持っている場合、何が起こるかありますか?両方の行が異なる列数を持つにもかかわらず、両方のraceSeriesPointsRulesを同じテーブルに格納することはできますか?

私の説明は明確です。前もって感謝します。

答えて

1

リストの独自の実装(実際の実装にすべてのメソッドを委譲しますが、要素は10個しか許可しません)をインデックス化したコレクションを使用します。この方法で、あなたは最大10個のアイテムを持っていることを確認し、あなたはまだ彼らのポジションを維持します。また、インデックスを見てポイントを簡単に計算することもできます。

http://docs.jboss.org/hibernate/core/3.3/reference/en/html/collections.html#collections-indexed

関連する問題