Reputation: 5024
I'm using JDO (with Datanucleus implementation) for a new project for the first time, and I'm having troubles defining 1-N unidirectional owned relation using JDO annotations. What I need is to have a collection of Subitems
in an Item
, such that a Subitem
doesn't have a reference to the owner:
@PersistenceCapable(detachable = "true")
public class Item {
...
@Persistent(defaultFetchGroup = "true")
Collection<Subitem> subitems;
...
}
It's all well and good, but how can I define which existing RDBMS column the relation maps to? AFAIK an owned 1-N is realized in a DB by creating a non-nullable table column in a child table but I don't have (and don't want) a parent reference class field in a Subitem
which I can then decorate with @Column(name="...")
annotation.
And how to properly use @ForeignKey
annotation in JDO3? The annotation accepts the name of the FK constraint but not the corresponding FK table and column specification. By definition a FK is a ref. constraint between two tables based on a common key, but I can't seem to specify the other table and a common key(@ForeginKey at Datanucleus JDO docs ).
Edit:
@Element(column="...")
annotation should be used instead:
@PersistenceCapable(detachable = "true")
public class Item {
...
@Persistent(defaultFetchGroup = "true")
@Element(column="itemId")
Collection<Subitem> subitems;
...
}
As it's clearly stated in the documentation links in the answer.
Upvotes: 0
Views: 858
Reputation: 15577
JDO (or JPA too for that matter) doesn't have "owned" relations, just relations (it is a term I've only ever heard of in relation to GAE's datastore, and you're not using that).
DataNucleus docs defines all such relations adequately IMHO so just navigate the menu from where you got to, for example http://www.datanucleus.org/products/accessplatform_3_1/jdo/orm/one_to_many_collection.html#fk_uni
http://www.datanucleus.org/products/accessplatform_3_1/jdo/orm/constraints.html#fk
Upvotes: 1