Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: Persistence API - magic? Date: Tue, 06 Sep 2011 19:01:52 -0700 Organization: A noiseless patient Spider Lines: 39 Message-ID: References: <7e3a3be9-8960-4b94-8028-2da962435fc8@u6g2000yqa.googlegroups.com> <14a59736-46ca-4642-bbbc-88b59a3ed401@glegroupsg2000goo.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 7 Sep 2011 02:02:13 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="5517"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/k7q+4FMnOUqVib8UL46cy+vxHO9jk/Lk=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.1) Gecko/20110830 Thunderbird/6.0.1 In-Reply-To: <14a59736-46ca-4642-bbbc-88b59a3ed401@glegroupsg2000goo.googlegroups.com> Cancel-Lock: sha1:Tgh6kQQxMK8iGSf9OH/3O4lOWjE= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7659 On 9/6/2011 6:26 PM, Lew wrote: > I'm pretty sure it's a Hibernatism, supplanted by persistence.xml for > all practical purposes. Thanks for pointing that out! > 'Country country;' with an '@ManyToOne'. NOT A COLUMN! It is an > OBJECT RELATIONSHIP, NOT A COLUMN! Oops, I didn't read his example carefully, and I missed that. So what's going on there is that Country is an entity too: @Entity public class Country { @Id int id; String name; // ? other properties... ... } And JPA will automatically put a foreign key in the table "Zip" that relates to the primary key in the table "Country" (I'm using class names here because you didn't specify differently, e.g. using @Table(name="A_TABLE_NAME")) and then JPA will do the join for you. However, watch out for lazy loading and detachment. > You specify the column inside the '@ManyToOne' annotation, not as a > field in the 'MyClass' (terrible name for an entity!). Yeah the "MyClass" was just to make it abundantly clear that my example wasn't related to the code posted by N. Roberts.