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


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

Persistence API - magic?

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.11.MISMATCH!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!u6g2000yqa.googlegroups.com!not-for-mail
From nroberts <roberts.noah@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Persistence API - magic?
Date Tue, 6 Sep 2011 15:52:21 -0700 (PDT)
Organization http://groups.google.com
Lines 68
Message-ID <7e3a3be9-8960-4b94-8028-2da962435fc8@u6g2000yqa.googlegroups.com> (permalink)
NNTP-Posting-Host 204.28.224.25
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
X-Trace posting.google.com 1315351025 21358 127.0.0.1 (6 Sep 2011 23:17:05 GMT)
X-Complaints-To groups-abuse@google.com
NNTP-Posting-Date Tue, 6 Sep 2011 23:17:05 +0000 (UTC)
Complaints-To groups-abuse@google.com
Injection-Info u6g2000yqa.googlegroups.com; posting-host=204.28.224.25; posting-account=yG8XEQkAAAAufx-VCHazgfIL-gE1KUVH
User-Agent G2/1.0
X-Google-Web-Client true
X-Google-Header-Order HUALESNKRC
X-HTTP-UserAgent Mozilla/5.0 (Windows NT 5.1; rv:6.0.1) Gecko/20100101 Firefox/6.0.1,gzip(gfe)
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7647

Show key headers only | View raw


I'm a little confused about how and why the persistence API is even
being used, let alone how it works, in this tutorial I just went
through.

I followed the instructions in this tutorial:
http://programming.manessinger.com/tutorials/an-eclipse-glassfish-java-ee-6-tutorial/

What I'm trying to figure out is how the "entity" classes that eclipse
created with the JPA tools work so I can make my own if I need to.

One tutorial on persistence that I found (
http://www.javaworld.com/javaworld/jw-01-2008/jw-01-jpa1.html?page=3 )
explains how to make them by hand but it uses an orm.xml or
annotations to tell Java what table and what columns to connect an
entity object with.  The eclipse stuff doesn't seem to do that at
all.  The orm.xml file exists, but it's practically empty containing
nothing but the root element and xml tag.  Here's an example entity:

@Entity
public class Zip extends com.manessinger.util.jpa.Entity implements
Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;

	private String code;

	private String name;

	//bi-directional many-to-one association to Country
    @ManyToOne
	private Country country;
 // ... getters and setters...
}

I was thinking that perhaps it was order based, but the order of the
columns in the zip table to do not match.  COUNTRY_ID comes between ID
and CODE.  The names are close but the case is different and the
"country" column is actually COUNTRY_ID.

The manessinger Entity base doesn't have anything interesting but some
id utility functions:

public abstract class Entity {
	public static boolean isId(Integer id)
	{
		return (id != null && id > 0);
	}

	public boolean hasId()
	{
		return isId(getId());
	}

	public abstract Integer getId();
}

The information doesn't seem to be at the query site either:

    	Query q = em.createQuery("select co from Country co");
    	result = (List<Country>)q.getResultList();

What are the rules that Java is using in order to tell what I want
here and do it?  As it stands it seems to almost be intuitively
interpreting what I want to do, which I know is impossible.  Why does
this code work?

Back to comp.lang.java.programmer | Previous | NextNext 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