Return-Path: Delivered-To: apmail-openjpa-users-archive@locus.apache.org Received: (qmail 94880 invoked from network); 8 May 2008 19:55:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 8 May 2008 19:55:13 -0000 Received: (qmail 7882 invoked by uid 500); 8 May 2008 19:55:14 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 7861 invoked by uid 500); 8 May 2008 19:55:14 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 7850 invoked by uid 99); 8 May 2008 19:55:14 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 May 2008 12:55:14 -0700 X-ASF-Spam-Status: No, hits=-2.0 required=10.0 tests=MIME_QP_LONG_LINE,RCVD_IN_DNSWL_MED,SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [193.109.254.147] (HELO mail27.messagelabs.com) (193.109.254.147) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 08 May 2008 19:54:19 +0000 X-VirusChecked: Checked X-Env-Sender: mvorburger@odyssey-group.com X-Msg-Ref: server-11.tower-27.messagelabs.com!1210276479!52791512!1 X-StarScan-Version: 5.5.12.14.2; banners=odyssey-group.com,-,- X-Originating-IP: [195.80.235.201] Received: (qmail 5259 invoked from network); 8 May 2008 19:54:39 -0000 Received: from unknown (HELO mail3.oams.com) (195.80.235.201) by server-11.tower-27.messagelabs.com with SMTP; 8 May 2008 19:54:39 -0000 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable Subject: RE: Question about @OneToMany Date: Thu, 8 May 2008 21:54:27 +0200 Message-ID: <12D996978341E849B21C51CC97F4771DB7E17F@mail3.oams.com> In-Reply-To: <17134828.post@talk.nabble.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Question about @OneToMany Thread-Index: AcixQvaIobPQDT4MThCoOfBcWFhYdAAANU+g References: <480E31E6.5040400@cioppino.net> <480F7AD0.5010708@cs.cmu.edu> <17124365.post@talk.nabble.com> <48230AE9.5030505@cs.cmu.edu> <17134828.post@talk.nabble.com> From: "Michael Vorburger" To: X-Virus-Checked: Checked by ClamAV on apache.org Hello, Similar=20situation=20here,=20and=20I=20wonder=20about=20people's=20though= ts=20&=20pros/cons regarding=20this: >=20Your=20solution=20(anotate=20"ModelObject=20parent;"=20with=20@ManyToO= ne=20instead of=20@Transient=20and=20add=20mappedBy=3D"parent"=20to=20@OneToMany)=20wor= ks,=20also=20for my=20application,=20but=20turns=20the=20uni-directional=20relation=20into=20= a bi-directional=20relation.=20=20And=20this=20bi-directional=20relation=20i= s=20more dificult=20to=20manage=20and=20not=20needed=20in=20our=20Java=20applicatio= n. Why=20is=20this=20"bi-directional=20relation=20is=20more=20dificult=20to=20= manage=20and=20not needed=20in=20our=20Java=20application"=20?=20=20If=20you=20let=20OpenJPA=20= deal=20with=20this=20for you=20with=20the=20Managed=20Inverses (http://openjpa.apache.org/docs/latest/manual/ref_guide_inverses.html), what's=20the=20problem=20with=20an=20additional=20field?=20=20Hide=20it=20= even=20-=20if=20for=20some reason=20you=20don't=20want=20to=20expose=20the=20bi-directionality=20to=20= the=20users=20of the=20object=20model=20for=20keep=20that=20'@ManyToOne=20ModelObject=20par= ent'=20as=20a private=20with=20no=20setters=20and=20getters=20-=20just=20to=20get=20the=20= desired=20mapping! What's=20the=20issue=20with=20this=20approach?=20=20(Portability=20and=20n= ot=20wanting=20to use=20Managed=20Inverses=20aside;=20but=20I=20don't=20know=20if=20that's=20= strong=20enough, you're=20using=20OpenJPA=20specific=20configuration=20elsewhere=20already,= =20and that's=20really=20what=20this=20is=20-=20a=20runtime=20configuration=20spe= cific=20to=20one=20JPA implementation.=20=20Other=20implementations=20may=20have=20a=20similar=20= feature?=20=20If not,=20worst=20case,=20when=20switching,=20manually=20code=20the=20logic=20= [with=20loop detection,=20if=20needed]). Regards, Michael -----Original=20Message----- From:=20Uden=20[mailto:udenvh@gmail.com]=20 Sent:=20jeudi,=208.=20mai=202008=2021:37 To:=20users@openjpa.apache.org Subject:=20Re:=20Question=20about=20@OneToMany Hi=20Andy,=20thanks=20for=20the=20quick=20response. In=20my=20application=20i=20had=20three=20tables=20generated=20(a=20master= ,=20a=20detail=20and=20a join=20table)=20for=20what=20i=20believed=20could=20be=20modelled=20by=20j= ust=20the=20master=20and a=20detail=20table=20(at=20least=20in=20traditional=20database=20modeling)= .=20So=20when=20i was=20looking=20for=20a=20solution=20to=20simplify=20my=20datamodel=20in=20= the=20database,=20i found=20this=20posting=20which=20looked=20similar=20to=20my=20problem=20an= d=20added=20my question. =20 I=20need=20to=20map=20the=20following=20Java=20classes=20(note=20i=20reuse= =20Marco's=20code example): @MappedSuperclass @Inheritance(strategy=3DInheritanceType.TABLE_PER_CLASS) class=20ModelObject=20{ =20=20=20=20=20=20=20=20@Id =20=20=20=20=20=20=20=20private=20int=20id =20=20=20=20=20=20=20=20@Transient =20=20=20=20=20=20=20=20ModelObject=20parent; =20=20=20=20=20=20=20=20@OneToMany(cascade=3D{CascadeType.ALL},=20fetch=3D= FetchType.EAGER) =20=20=20=20=20=20=20=20List=20children; =20=20=20=20=20=20=20=20..... } @Entity class=20Company=20extends=20ModelObject=20{ } @Entity class=20Employer=20extends=20ModelObject=20{ } to=20the=20folowing=20database=20tables: COMPANY=20 (ID=20=20=20=20=20(PK) ,=20... ) and=20EMPLOYEE (ID=20=20=20=20=20(PK) ,COMPANY_ID=20=20=20=20(FK=20to=20COMPANY.ID) ,=20... ) In=20Marco's=20original=20question=20he=20indicates=20that=20in=20his=20ca= se=20"openjpa create=204=20tables=20(Company,=20Company_children,=20Emplpyer=20and Employer_children).".=20 Your=20solution=20(anotate=20"ModelObject=20parent;"=20with=20@ManyToOne=20= instead=20of @Transient=20and=20add=20mappedBy=3D"parent"=20to=20@OneToMany)=20works,=20= also=20for=20my application,=20but=20turns=20the=20uni-directional=20relation=20into=20a bi-directional=20relation.=20 And=20this=20bi-directional=20relation=20is=20more=20dificult=20to=20manag= e=20and=20not needed=20in=20our=20Java=20application.=20It=20does=20however=20results=20= in=20a=20simpler datamodel.=20 Your=20second=20solution=20changes=20the=20direction=20(or=20ownership)=20= of=20the relation=20in=20the=20Java=20model. So=20it=20seems=20we=20have=20to=20trade=20a=20simplified=20database=20dat= amodel=20versus=20a simplified=20Java=20datamodel. Or=20is=20there=20an=20other=20solution? thanks, Uden hazen=20wrote: >=20 >=20Hi=20Uden, >=20 >=20If=20you'd=20rather=20keep=20the=20relation=20unidirectional=20just=20= remove=20the=20 >=20`children`=20field--=20the=20`parent`=20field=20alone=20is=20enough=20= to=20encode=20the=20 >=20relation=20without=20recourse=20to=20a=20separate=20join=20table.=20Ei= ther=20way,=20I=20 >=20don't=20see=20how=20the=20quoted=20section=20below=20results=20in=20a=20= join=20table.=20Both=20 >=20fields=20rely=20solely=20on=20a=20"parent_id"=20column=20within=20the=20= "ModelObject"=20 >=20table,=20not=20on=20some=20other=20join=20table.=20Am=20I=20missing=20= something? >=20 >=20Andy >=20 >=20Uden=20wrote: >>=20The=20solution=20quoted=20below=20but=20has=20a=20consequence=20for=20= the=20Java=20class model: >>=20the >>=20OneToMany=20relationship=20becomes=20bi-directional=20instead=20of uni-directional.=20 >>=20 >>=20What=20is=20the=20reason=20for=20creating=20the=20join-table?=20 >>=20 >>=20I=20thought=20(based=20on=20my=20database=20experience)=20that=20a=20= join-table=20is=20only >>=20required=20for=20ManyToMany=20relationships. >>=20If=20you=20look=20at=20the=20data=20in=20the=20join-table=20of=20a=20= uni-directional=20 >>=20relation=20(no=20mappedBy=20attribute),=20the=20relation=20between=20= the=20join-table >>=20and=20master=20table=20is=20always=20OneToOne,=20so=20this=20relation= =20could=20be=20 >>=20handled=20by=20a=20FK-field=20in=20the=20detail-table. >>=20 >>=20thanks=20for=20your=20explanation, >>=20Uden >>=20 >>=20 >>=20Andy=20Schlaikjer-2=20wrote: >>>=20Marco=20Schwarz=20wrote: >>>>=20How=20can=20I=20make=20only=202=20tables? >>>=20Here's=20my=20guess: >>> >>>=20First,=20use=20the=20"mappedBy"=20property=20of=20the=20@OneToMany=20= annotation,=20 >>>=20like >>>=20this: >>> >>>=20@Entity >>>=20class=20ModelObject=20{ >>>=20=20=20=20... >>> >>>=20=20=20=20@ManyToOne >>>=20=20=20=20ModelObject=20parent; >>> >>>=20=20=20=20@OneToMany(mappedBy=3D"parent") >>>=20=20=20=20List=20children; >>> >>>=20=20=20=20... >>>=20} >>> >>>=20This=20way,=20an=20extra=20join=20table=20won't=20be=20necessary=20t= o=20encode=20the=20 >>>=20parent=20child=20relationship.=20Only=20the=20"parent_id"=20column=20= in=20the "ModelObject" >>>=20table=20will=20be=20used=20to=20encode=20the=20relationship. >>> >>=20 >=20 >=20 -- View=20this=20message=20in=20context: http://www.nabble.com/Question-about-%40OneToMany-tp16840368p17134828.ht ml Sent=20from=20the=20OpenJPA=20Users=20mailing=20list=20archive=20at=20Nabb= le.com. ____________________________________________________________ =95=20This=20email=20and=20any=20files=20transmitted=20with=20it=20are=20C= ONFIDENTIAL=20and=20intended =20=20solely=20for=20the=20use=20of=20the=20individual=20or=20entity=20to=20= which=20they=20are=20addressed. =95=20Any=20unauthorized=20copying,=20disclosure,=20or=20distribution=20of= =20the=20material=20within =20=20this=20email=20is=20strictly=20forbidden. =95=20Any=20views=20or=20opinions=20presented=20within=20this=20e-mail=20a= re=20solely=20those=20of=20the =20=20author=20and=20do=20not=20necessarily=20represent=20those=20of=20Ody= ssey=20Financial Technologies=20SA=20unless=20otherwise=20specifically=20stated. =95=20An=20electronic=20message=20is=20not=20binding=20on=20its=20sender.=20= Any=20message=20referring=20to =20=20a=20binding=20engagement=20must=20be=20confirmed=20in=20writing=20an= d=20duly=20signed. =95=20If=20you=20have=20received=20this=20email=20in=20error,=20please=20n= otify=20the=20sender=20immediately =20=20and=20delete=20the=20original.