Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #7658

Re: Persistence API - magic?

From Lew <lewbloch@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Re: Persistence API - magic?
Date 2011-09-06 18:26 -0700
Organization http://groups.google.com
Message-ID <14a59736-46ca-4642-bbbc-88b59a3ed401@glegroupsg2000goo.googlegroups.com> (permalink)
References <7e3a3be9-8960-4b94-8028-2da962435fc8@u6g2000yqa.googlegroups.com> <j46ev4$fpo$1@dont-email.me>

Show all headers | View raw


markspace wrote:
> I'm actually working on learning some JPA/JSF stuff right now too.  The 
> orm.xml stuff confuses me because I haven't seen it before.  I'm used to 
> a persistence.xml file being used.  I'm concerned about versions here 
> and portability, because you seem to be configuring the tool directly, 
> and not using the JPA config file.
> 
> Does anyone know what this config file is about?  What version of the 
> library uses it?  It either seems specific to his library, and therefore 
> non-portable, or it's really old.

I'm pretty sure it's a Hibernatism, supplanted by persistence.xml for all practical purposes.

nroberts wrote: 
>> COUNTRY_ID comes between ID
>> and CODE.  The names are close but the case is different and the
>> "country" column is actually COUNTRY_ID.

"Country" in JPA is NOT A COLUMN!  It's a type.  

It will contain a column for the id, or perhaps more than one.  But it's a representation of the "country" table, not just one column.

Get this, because it's the biggest single mistake people make with JPA.  'Country' is an entity!  It is an entity.  It is not a column.  It is an entity.

A whole entity, with attributes.  There are no columns in objects.  Classes don't have columns, they have attributes or fields.  Tables don't have fields, they have columns.  JPA is about objects, not tables.  Country is a type, that is, an entity in an object-oriented sense.  

I'm being deliberately repetitive here because it is the key.  COUNTRY IS NOT A COLUMN!

> @Entity
> public class MyClass {
>    @Id
>    int id;
>    @Column( name="COUNTRY_ID" )
>    String country;

NO!  NO!  NO!  NO!  

'Country country;' with an '@ManyToOne'.  NOT A COLUMN!  It is an OBJECT RELATIONSHIP, NOT A COLUMN!

Bad JPA there, bad!

>   ...
> }

You specify the column inside the '@ManyToOne' annotation, not as a field in the 'MyClass' (terrible name for an entity!).

-- 
Lew

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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