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 :/