2012-03-04 5 views
0

次のオブジェクトのテーブルモデルを作成するのに役立ちます。 は、クラスjテーブルとハイバーネート

public class Class1 implements Serializable { 

    private Long id = null; 
    private String name = null; 
    private Set <Class2> transaction = new HashSet <Class2>(); 

    get and set ... 
} 

public class Class2 implements Serializable { 

    private Long class1Id = null; 
    private String field1 = null; 
    private Class1 class1 = null; 

    get and set ... 
} 

1対多があるとします。 テーブルの表示ID、名前、フィールド1。 1、 "John"、asd; 1、 "John"、2; .... このようなもの。何ができるのかの例を挙げてください。

+0

あなたの質問がありますか?何を試しましたか? Hibernateはこの質問にどのように関連していますか? –

+0

クラス内のオブジェクトの数は、10と言いますが、それぞれの数は任意の数になることがあります。どのようにテーブルに、これらのすべての行をもたらす?私の英語の申し訳ありません – user970359

答えて

1

Class121のインスタンスとClass2のインスタンスを含むクラスClass1WithTransactionを作成します。 Class1のインスタンスを反復した後、その取引のそれぞれの上に、そしてList<Class1WithTransaction>を移入:あなたはこのリストを持っていたら

List<Class1WithTransaction> list = new ArrayList<Class1WithTransaction>(); 
for (Class1 c1 : theObjects) { 
    if (c1.getTransactions().isEmpty()) { 
     list.add(new Class1WithTransaction(c1, null)); 
    } 
    else { 
     for (Class2 transaction : c1.getTransactions()) { 
      list.add(new Class1WithTransaction(c1, transaction)) 
     } 
    } 
} 

は、あなたはそれの周りにテーブルモデルを作成する必要があります。テーブルの各行はClass1WithTransactionのインスタンスです。

+0

thx、それをやろう – user970359