@Column defines the column into which a field is persisted. I can't see why you want to use the same column for three fields. If you don't want to store the address_id on OmSite you can use the @Persistent(mappedBy="<OmSite field on OmAddress>") annotation [1].
HTH [1] http://www.datanucleus.org/products/accessplatform/jdo/orm/one_to_one.html On Tue, Jan 7, 2014 at 11:54 AM, <[email protected]> wrote: > Consider this following scenario: > > public class OmSite implements java.io.Serializable { > > //OmSitePK.class is also created as per the specifications > //for these two fields. No issue with that > @Persistent(primaryKey = "true", dependent = "false") > @Column(allowsNull = "false", name = "site_id") > private String siteId; > > @Persistent(primaryKey = "true", dependent = "false") > @Column(allowsNull = "false", name = "org_id") > private String orgId; > > @Persistent(columns = {@Column(name="address_id", target = "address_id"), > @Column(name="org_id", target = "org_id")}) > @Optional > private OmAddress omAddress; > > @Persistent(columns = { @Column(name = "location_id"), > @Column(name = "org_id")}) > @Optional > private OmGeoLocation omGeoLocation; > //Corresponding PK classes also created as per the specifications. > > //getters and setters > > } > > > Here I have 1 composite PK(site_id, org_id), 2 composite FK's > OmGeoLocation(location_id,org_id), OmAddress(address_id, org_id). > As you can see same column org_id is being used/referred at 3 places > > With this mapping, when OmSite is constructed with its PK fields(orgId, > siteId) and other mandatory fields. But not FK fields(omGeoLocation, > omAddress), I have got not-null constraint error for one of the fields in > compiste PK that is org_id. > > And when I construct OmSite by setting FKS (omGeoLocation, omAddress)also > with org_id being same accorss PK and FK's, org_id value is being sent to > Database. > > > I suspect that org_id column is set when all the fields are set which use > org_id column. > This is not valid behaviour. Because OmGeoLocation and OmAddress are optional. > > Please help on this issue > > Thanks > Ranganath > > BR > Ranganath Varma > > > The information contained in this electronic message and any attachments to > this message are intended for the exclusive use of the addressee(s) and may > contain proprietary, confidential or privileged information. If you are not > the intended recipient, you should not disseminate, distribute or copy this > e-mail. Please notify the sender immediately and destroy all copies of this > message and any attachments. > > WARNING: Computer viruses can be transmitted via email. The recipient should > check this email and any attachments for the presence of viruses. The company > accepts no liability for any damage caused by any virus transmitted by this > email. > > www.wipro.com
