Return-Path: Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: (qmail 64916 invoked from network); 14 Feb 2011 09:15:17 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Feb 2011 09:15:17 -0000 Received: (qmail 58278 invoked by uid 500); 14 Feb 2011 09:15:17 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 58112 invoked by uid 500); 14 Feb 2011 09:15:14 -0000 Mailing-List: contact dev-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list dev@openjpa.apache.org Received: (qmail 58104 invoked by uid 99); 14 Feb 2011 09:15:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Feb 2011 09:15:13 +0000 X-ASF-Spam-Status: No, hits=3.7 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of fakod666@googlemail.com designates 209.85.214.174 as permitted sender) Received: from [209.85.214.174] (HELO mail-iw0-f174.google.com) (209.85.214.174) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Feb 2011 09:15:08 +0000 Received: by iwn9 with SMTP id 9so4902814iwn.33 for ; Mon, 14 Feb 2011 01:14:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=mKGiMzYjQfimcVxajcHUDyLKqAQOAlIflQzrj963SHM=; b=GtpCIVpGAC18jHwYSpxcBIPDNBIGCmFxihqG1Rfw9+6K0tQvsv7dMYd6YoOl3zkniQ yUsRXnkWn/rPiPVSds5a7jxlfsLNLwhYN1ku0eEipzZtLAq6wXvbC3/Zpz/SAuCdr4R/ 0c4HDWann/AAHHsb8b4UjJ/vcGq/c/HE32X2M= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=HCsXM7C4ct1pqhpEfkFo4Yi9ag600NuP6OO7hguLUrj2BRjzzWk7Rc5+1jwTlkmVz7 +T/pRg9up10SbfP/6Z/bA/Vot0vXcsj0+1srNEqnRMq5xWjiiGhnAMO+NSAwnqSzbnVj 7vHox7FLz+vZV2wCsqhrsDSTCgWnzSJvLmh8I= MIME-Version: 1.0 Received: by 10.42.5.201 with SMTP id 9mr4574445icx.300.1297674887720; Mon, 14 Feb 2011 01:14:47 -0800 (PST) Received: by 10.42.139.6 with HTTP; Mon, 14 Feb 2011 01:14:47 -0800 (PST) In-Reply-To: References: Date: Mon, 14 Feb 2011 10:14:47 +0100 Message-ID: Subject: Fwd: Composite Id Mapping question From: Christopher Schmidt To: dev@openjpa.apache.org Content-Type: multipart/alternative; boundary=005045014712b76e8c049c3a7a23 --005045014712b76e8c049c3a7a23 Content-Type: text/plain; charset=ISO-8859-1 Hi, I posted this already to the user list and got no answer... I think there is an error while retrieving a instance of ObjectItemAssociationStatus. Both Id fields (subjObjItem and objObjItem) are null in this case. The query I am executing is: "select o from ObjectItemAssociationStatus o where o.ix = ?1 AND o.rptd.id = ?2" Would be nice if someone could have a look at this. Christopher ---------- Forwarded message ---------- From: Christopher Schmidt Date: Fri, Feb 11, 2011 at 11:33 AM Subject: Composite Id Mapping question To: users@openjpa.apache.org Hi all, I have a problem with the best mapping of two tables: obj_item_assoc and obj_item_assoc_stat. Both share 3 of its primary keys. The "XXX_obj_item" primary keys are a fk's to the entity ObjectItem - thats why I modeled it as ManyToOne. Creation works fine, but if I query for ObjectItemAssociationStatus the fields subjObjItem and objObjItem are null !? Is this because I used their columns in ObjectItemAssociation? What would be the best way to map this (assuming that I did not do that)? Thanks for helping (I skipped some fields in the listings below) -- Christopher twitter: @fakod blog: http://blog.fakod.eu TABLE obj_item_assoc ( subj_obj_item_id numeric(20,0) NOT NULL, obj_obj_item_id numeric(20,0) NOT NULL, obj_item_assoc_ix numeric(20,0) NOT NULL, CONSTRAINT obj_item_assoc_pkey PRIMARY KEY (subj_obj_item_id, obj_obj_item_id, obj_item_assoc_ix), CONSTRAINT obj_item_assoc_obj_obj_item_id_fkey FOREIGN KEY (obj_obj_item_id) REFERENCES obj_item (obj_item_id), CONSTRAINT obj_item_assoc_subj_obj_item_id_fkey FOREIGN KEY (subj_obj_item_id) REFERENCES obj_item (obj_item_id) ) TABLE obj_item_assoc_stat ( subj_obj_item_id numeric(20,0) NOT NULL, obj_obj_item_id numeric(20,0) NOT NULL, obj_item_assoc_ix numeric(20,0) NOT NULL, obj_item_assoc_stat_ix numeric(20,0) NOT NULL, CONSTRAINT obj_item_assoc_stat_pkey PRIMARY KEY (subj_obj_item_id, obj_obj_item_id, obj_item_assoc_ix, obj_item_assoc_stat_ix), CONSTRAINT obj_item_assoc_stat_subj_obj_item_id_fkey FOREIGN KEY (subj_obj_item_id, obj_obj_item_id, obj_item_assoc_ix) REFERENCES obj_item_assoc (subj_obj_item_id, obj_obj_item_id, obj_item_assoc_ix) ) @Entity @Table(name = "obj_item_assoc_stat") @IdClass(ObjectItemAssociationStatus.ObjectItemAssociationStatusId.class) public class ObjectItemAssociationStatus extends LoggableEntity { @Id @Column(name = "obj_item_assoc_stat_ix", nullable = false, length = 20) protected BigInteger ix; @Id @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "subj_obj_item_id", nullable = false, updatable = false) protected ObjectItem subjObjItem; @Id @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "obj_obj_item_id", nullable = false, updatable = false) protected ObjectItem objObjItem; @Id @ManyToOne(fetch = FetchType.EAGER) @JoinColumns({@JoinColumn(name = "subj_obj_item_id", referencedColumnName = "subj_obj_item_id", nullable = false), @JoinColumn(name = "obj_obj_item_id", referencedColumnName = "obj_obj_item_id", nullable = false), @JoinColumn(name = "obj_item_assoc_ix", referencedColumnName = "obj_item_assoc_ix", nullable = false)}) protected ObjectItemAssociation objItemAssoc; . . . } @Entity @Table(name = "obj_item_assoc") @IdClass(ObjectItemAssociation.ObjectItemAssociationId.class) public class ObjectItemAssociation extends NonIndependentEntity { @Id @Column(name = "obj_item_assoc_ix", nullable = false, length = 20) protected BigInteger ix; @Id @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "subj_obj_item_id", nullable = false, updatable = false) protected ObjectItem subjObjItem; @Id @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "obj_obj_item_id", nullable = false, updatable = false) protected ObjectItem objObjItem; . . . } -- Christopher twitter: @fakod blog: http://blog.fakod.eu --005045014712b76e8c049c3a7a23--