2

I've been trying to do a simple one to many object binding in DataNucleus JDO. It's just two classes (i stripped a simple fields):

@PersistenceCapable(table="ORDER",schema="mgr")
public class Order {
    @PrimaryKey(column="id")
    @Persistent(valueStrategy=IdGeneratorStrategy.NATIVE,column="id")    
    private Long id;

    @Persistent(defaultFetchGroup="false",column="customer_id")
    @Element(column="customer_id")  
    private Customer customer;
}

And a class Customer having a list of orders

@PersistenceCapable(table="customer",schema="mgr",identityType=IdentityType.DATASTORE)
@DatastoreIdentity(strategy=IdGeneratorStrategy.NATIVE)
public class Customer {
    @PrimaryKey
    @Persistent(valueStrategy=IdGeneratorStrategy.NATIVE,column="id")    
    private Long id;

    @Persistent(mappedBy="customer") 
    private List<Order> orders;
}

The database table setup is extremely simple(a table for customer and a table for orders with a foreign key (customer_id) referencing customer). Yet, when i try to insert some orders for customer i receive an error

javax.jdo.JDODataStoreException: Insert of object "test.Order@17dd585" using statement "INSERT INTO ORDER (USER_COMMENT,ORDER_DATE,STATUS,CUSTOMER_ID,ORDERS_INTEGER_IDX) VALUES (?,?,?,?,?)" failed : Unknown column 'ORDERS_INTEGER_IDX' in 'field list'

Somehow DataNucleus is assuming, there is a column ORDERS_INTEGER_IDX (such column does not exist in the database). The only idea, that came to my mind is http://www.datanucleus.org/products/datanucleus/jdo/metadata_xml.html

In some situations DataNucleus will add a special datastore column to a join table so that collections can allow the storage of duplicate elements. This extension allows the specification of the column name to be used. This should be specified within the field at the collection end of the relationship. JDO2 doesnt allow a standard place for such a specification and so is an extension tag.

So cool! 'in some situations'. I have no idea how to make my situation not to be a subset of 'some situations' but I have no idea, how to get this working. Perhaps someone has allready met the "INTEGER_IDX" problem? Or (it is also highly possible) - im not binding the data correctly :/

4

1 に答える 1

3

したがって、自分でスキーマを作成します。スキーマがメタデータと矛盾しています。メタデータをスキーマに対して検証せずに永続化を実行すると、例外が発生します。DataNucleus は、メタデータに対してスキーマを作成または検証するための SchemaTool を提供するため、問題を検出できます。

インデックス付きリストを使用しているため、各要素のインデックスが必要です (または、要素がどの位置にあるかを知るにはどうすればよいでしょうか?)。インデックスがあるとどのように仮定できますか?それは、インデックス付きリストを定義する JDO 仕様 (公開されています) と呼ばれるものです。要素の位置を保存したくない場合は、List (要素の位置を保持するための Java util クラス) を使用しないでください。位置情報は必要ないため、Set を使用することをお勧めします (したがって、インデックスなし)。

また、データストア ID としてマークされたクラスがあり、主キーがあります。それは矛盾です...あなたはどちらか一方を持っています. ドキュメントでは、そのすべてと、1-N リスト関係 ("JDO API" -> "Mapping" -> "Fields/Properties" -> "1-N Relations" -> "Lists" または"セット")

于 2013-04-01T17:54:47.840 に答える