Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #7659
| From | markspace <-@.> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Persistence API - magic? |
| Date | 2011-09-06 19:01 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <j46jb5$5cd$1@dont-email.me> (permalink) |
| References | <7e3a3be9-8960-4b94-8028-2da962435fc8@u6g2000yqa.googlegroups.com> <j46ev4$fpo$1@dont-email.me> <14a59736-46ca-4642-bbbc-88b59a3ed401@glegroupsg2000goo.googlegroups.com> |
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.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
Persistence API - magic? nroberts <roberts.noah@gmail.com> - 2011-09-06 15:52 -0700
Re: Persistence API - magic? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-09-06 21:40 -0300
Re: Persistence API - magic? nroberts <roberts.noah@gmail.com> - 2011-09-07 07:56 -0700
Re: Persistence API - magic? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-09-07 17:34 -0300
Re: Persistence API - magic? markspace <-@.> - 2011-09-06 17:47 -0700
Re: Persistence API - magic? Lew <lewbloch@gmail.com> - 2011-09-06 18:26 -0700
Re: Persistence API - magic? markspace <-@.> - 2011-09-06 19:01 -0700
Re: Persistence API - magic? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-09-07 06:14 -0300
Re: Persistence API - magic? nroberts <roberts.noah@gmail.com> - 2011-09-07 08:10 -0700
Re: Persistence API - magic? markspace <-@.> - 2011-09-07 09:15 -0700
Re: Persistence API - magic? Lew <lewbloch@gmail.com> - 2011-09-07 10:36 -0700
Re: Persistence API - magic? markspace <-@.> - 2011-09-07 10:57 -0700
Re: Persistence API - magic? Lew <lewbloch@gmail.com> - 2011-09-07 11:06 -0700
Re: Persistence API - magic? Lew <lewbloch@gmail.com> - 2011-09-06 18:09 -0700
Re: Persistence API - magic? Roedy Green <see_website@mindprod.com.invalid> - 2011-09-08 12:32 -0700
Re: Persistence API - magic? "John B. Matthews" <nospam@nospam.invalid> - 2011-09-08 19:23 -0400
csiph-web