2010-12-21 5 views
0

Ich habe einen POJO und einen Winterschlaf, der Ganzzahlen enthält, die das Punktesystem für eine bestimmte Rasse angeben (dh 1. Platz = 100, 2. Platz = 70 ......) und sich gefragt haben, ob es eine Möglichkeit ist, ein Array-Objekt und ordnen Sie es in meiner HBM-Datei und Pojo-Klasse.Hibernate-Arrays?

hier ist, wie es im Moment aussieht:

<?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> 

Hier ist meine pojo unter:

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; 
    } 



} 

Wie Sie sich eine Hack Job sehen und würde gerne wissen, ob ich verwenden kann Arrays im Ruhezustand, um Spalten mit array.size zu erstellen und sie mit Ints zu füllen. dies wird meinen pojo sehr klein machen und Logik in der Berechnung der Punkte machen, die ein Rennfahrer auf der Position, die sie beendet haben, angesammelt hat:

racer A beendet 2., Rennfahrer eine Position = 2;

Select column.pos2 von race_series_points_rules wo .........

edit: eine andere Frage ist, was passiert, wenn Rennserie A nur 10 Positionen und Race Series B 16 hat? können beide raceSeriesPointsRules in derselben Tabelle gespeichert werden, obwohl beide Zeilen unterschiedliche Spaltenanzahl haben?

Ich hoffe, meine Erklärungen sind klar. Danke im Voraus.

Antwort

1

Ich würde dafür eine indizierte Sammlung verwenden, vielleicht sogar Ihre eigene Implementierung von List (Delegieren aller Methoden an die tatsächliche Implementierung, aber nur 10 Elemente zulassen). Auf diese Weise stellen Sie sicher, dass Sie höchstens 10 Elemente haben und Ihre Positionen behalten. Sie können die Punkte auch einfach berechnen, indem Sie auf den Index schauen.

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