Sanjeeb Kumar has written up a walkthrough for using EJB3 persistence in a simple web application. While this has been done elsewhere (and referenced on TSS and other sites), this entry is interesting because of its simple and clear nature and references, which make it easy to follow.
Other interesting facets: it uses the Glassfish EJB3 reference implementation (as opposed to Hibernate 3, although it'd be interesting to see if the use of Hibernate changed anything in the walkthrough), and also references Java2DB, a tool provided in Glassfish that can create a database schema from a set of entity beans.
-
Introduction to using Java Persistence API in a web application (24 messages)
- Posted by: Joseph Ottinger
- Posted on: December 05 2005 08:59 EST
Threaded Messages (24)
- Generating tables from Beans by Matt Giacomini on December 05 2005 11:13 EST
- Generating tables from Beans by Matt Giacomini on December 05 2005 11:14 EST
- Matt, did you like the 'simple and clear nature' of this entry? by Sujan J20 on December 05 2005 11:59 EST
- Matt, did you like the 'simple and clear nature' of this entry? by Matt Giacomini on December 05 2005 12:38 EST
- Generating tables from Beans by Anshuman Purohit on December 05 2005 14:36 EST
-
JPA 1.0 and EJB 3.0 specs by Randy Schnier on December 05 2005 03:08 EST
-
JPA 1.0 and EJB 3.0 specs by George Jiang on December 05 2005 05:25 EST
- JPA 1.0 and EJB 3.0 specs by George Jiang on December 05 2005 05:31 EST
-
JPA 1.0 and EJB 3.0 specs by George Jiang on December 05 2005 05:36 EST
- JPA 1.0 and EJB 3.0 specs by George Jiang on December 06 2005 05:35 EST
- JPA 1.0 and EJB 3.0 specs by Bostjan Dolenc on December 06 2005 05:47 EST
-
JPA 1.0 and EJB 3.0 specs by George Jiang on December 05 2005 05:25 EST
-
JPA 1.0 and EJB 3.0 specs by Randy Schnier on December 05 2005 03:08 EST
- Using Persistence API in Java SE by Mitesh Meswani on December 05 2005 15:23 EST
- Article vs. Hibernate EJB3? by Dan Greening on December 05 2005 15:43 EST
-
Re: Article vs. Hibernate EJB3? by Dan Greening on December 06 2005 08:52 EST
-
Re: Article vs. Hibernate EJB3? by Randy Schnier on December 06 2005 11:21 EST
-
Re: Article vs. Hibernate EJB3? by Dan Greening on December 06 2005 04:30 EST
- Is .jar enough or do I need .par & .ejb3 etc? by Sahoo Sanjeeb on December 07 2005 12:11 EST
- Re: Article vs. Hibernate EJB3? by Debu Panda on December 07 2005 04:35 EST
- Re: Article vs. Hibernate EJB3? by Sahoo Sanjeeb on December 07 2005 09:06 EST
-
Re: Article vs. Hibernate EJB3? by Dan Greening on December 06 2005 04:30 EST
-
Re: Article vs. Hibernate EJB3? by Randy Schnier on December 06 2005 11:21 EST
-
Article vs. Hibernate EJB3? by Sujan J20 on December 06 2005 09:22 EST
- Article vs. Hibernate EJB3? by Matt Giacomini on December 06 2005 01:59 EST
- Article vs. Hibernate EJB3? by Emmanuel Bernard on December 06 2005 04:16 EST
-
Re: Article vs. Hibernate EJB3? by Dan Greening on December 06 2005 08:52 EST
- How to enable Java2DB feature in glassfish? by Sahoo Sanjeeb on December 05 2005 16:17 EST
- Java2DB feature now supported for all databases in glassfish by Pramod Gopinath on December 06 2005 20:48 EST
-
Generating tables from Beans[ Go to top ]
- Posted by: Matt Giacomini
- Posted on: December 05 2005 11:13 EST
- in response to Joseph Ottinger
First let me say that I have read the spec and built a couple very small sample applications myself. Based on my expirence so far I really like EJB and think that the people involved did a great job bringing it together.
I'm also sure that once Rod and co. build a wrapper for EJB3 that the spring people will be fine with it too ;)
My question is weather there are plans for javax.persistence to become part of Java SE? It seems to me that all of Java could benefit from this API not just application server based applications. -
Generating tables from Beans[ Go to top ]
- Posted by: Matt Giacomini
- Posted on: December 05 2005 11:14 EST
- in response to Matt Giacomini
Sorry for the title I was orig going to ask a different question but changed my mind. -
Matt, did you like the 'simple and clear nature' of this entry?[ Go to top ]
- Posted by: Sujan J20
- Posted on: December 05 2005 11:59 EST
- in response to Matt Giacomini
First let me say that
Stop - You have to. First, I will let you say whether you liked the 'simple and clear nature' and 'easy to follow feature' of this article. Then, you may proceed with your usual question(s).
TSS has done and is doing a superb job of highlighting the very good work of 'Sanjeeb Kumar' (here) and of 'Binod P.G' (http://www.theserverside.com/news/thread.tss?thread_id=37863#192695).
Nice!!! <= this is admiration for TSS for its job of coverage. Ok. And Thank you. -
Matt, did you like the 'simple and clear nature' of this entry?[ Go to top ]
- Posted by: Matt Giacomini
- Posted on: December 05 2005 12:38 EST
- in response to Sujan J20
First, I will let you say whether you liked the 'simple and clear nature' and 'easy to follow feature' of this article.
ha ha ha Sorry but I can't say, I didn't bother reading it. I'm just taking advantage of the fact that this post relates to EJB3 ;) -
Generating tables from Beans[ Go to top ]
- Posted by: Anshuman Purohit
- Posted on: December 05 2005 14:36 EST
- in response to Matt Giacomini
Yes. If I recollect it right, Linda (JSR 220 EJB3 Spec Lead) mentioned in JavaPolis 2004 that this API is going to be part of JSE as well.
So, you are right (and community believes) that all of Java could benifit from this API.
--Anshuman -
JPA 1.0 and EJB 3.0 specs[ Go to top ]
- Posted by: Randy Schnier
- Posted on: December 05 2005 15:08 EST
- in response to Anshuman Purohit
The Java Persistence API spec (JPA 1.0) is actually a separate and distinct spec from EJB 3.0, and EJB 3.0 refers to JPA for its POJO persistence model. One reason the two were separated into individual specs (though produced by the same expert group) was precisely so JPA could become part of JavaSE at some point. (There was a very conscientous effort to make sure that JPA, as defined in the spec, could be used in either SE or EE environments.) It also helps separate the concepts of the persistence model (JPA) from the component execution model (EJB3). This is good, since these two models being smashed together in EntityBeans was one of the factors EB's started to be viewed as 'heavyweight'.
Randy Schnier
IBM, member JSR 220 expert group -
JPA 1.0 and EJB 3.0 specs[ Go to top ]
- Posted by: George Jiang
- Posted on: December 05 2005 17:25 EST
- in response to Randy Schnier
Hey, the name EJB3 has been overly sold to the developer community as the POJO persistence solution for so long, it is too late to correct the mistake. Even though the acronym POJO itself was coined by Martine Fowler et al to make using plain Java object instead of heavyweight EJB more sexy (thus more attractive to developers who want to be sexy). -
JPA 1.0 and EJB 3.0 specs[ Go to top ]
- Posted by: George Jiang
- Posted on: December 05 2005 17:31 EST
- in response to George Jiang
Especially when this is not in the interest of some "EJB3 vendors" (to give the stuff a proper name). -
JPA 1.0 and EJB 3.0 specs[ Go to top ]
- Posted by: George Jiang
- Posted on: December 05 2005 17:36 EST
- in response to George Jiang
Even though the acronym POJO itself was coined by Martine Fowler et al to make using plain Java object instead of heavyweight EJB more sexy (thus more attractive to developers who want to be sexy).
Five years ago! -
JPA 1.0 and EJB 3.0 specs[ Go to top ]
- Posted by: George Jiang
- Posted on: December 06 2005 17:35 EST
- in response to George Jiang
Even though the acronym POJO itself was coined by Martine Fowler et al to make using plain Java object instead of heavyweight EJB more sexy (thus more attractive to developers who want to be sexy).
Five years ago!
Here it is:
http://www.martinfowler.com/bliki/POJO.html -
JPA 1.0 and EJB 3.0 specs[ Go to top ]
- Posted by: Bostjan Dolenc
- Posted on: December 06 2005 05:47 EST
- in response to George Jiang
Hey, the name EJB3 has been overly sold to the developer community as the POJO persistence solution for so long, it is too late to correct the mistake.
OTOH POJO persistence has been oversold, too. After having to choose between 5+ MB of generated SQL queries or writing a separate finder for each access case in a proprietary language with shabby tool support, plain old SQL doesn't look that bad anymore. -
Using Persistence API in Java SE[ Go to top ]
- Posted by: Mitesh Meswani
- Posted on: December 05 2005 15:23 EST
- in response to Matt Giacomini
My question is weather there are plans for javax.persistence to become part of Java SE? It seems to me that all of Java could benefit from this API not just application server based applications.
This might not be the direct answer to your question.
It is possible to use the Persistence API from a JavaSE application even today. Look at https://glassfish.dev.java.net/javaee5/persistence/entity-persistence-support.html#Java_SE
for a description. -
Article vs. Hibernate EJB3?[ Go to top ]
- Posted by: Dan Greening
- Posted on: December 05 2005 15:43 EST
- in response to Matt Giacomini
I have implemented an EJB3 persistence unit, I've read most of the released documents regarding EJB3 persistence, from both Sun and JBoss, and I have these comments.
1. Very nice, clear and helpful article. Thank you Sanjeeb.
2. Hibernate-EJB3 docs reference a ".ejb3" file which encompasses the persistence unit. Sanjeeb implies this file can be in a simple .jar file. Let me say "massive thank you" to whoever is responsible, if in fact EJB3s can be captured in a simple JAR. The packaging issues for ".ejb3" were going to be pretty annoying.
3. The em.find method was not well documented in Hibernate-EJB3 docs, so it was nice to see it used here.
4. I didn't know that @Id was required, and that it was mentioned in the article saved me some time.
5. Just a plug for the Hibernate-EJB3 folks: That microcontainer is way-nice for debugging these EJB3 entity beans.
What can we do to encourage the release of this great persistence technology? -
Re: Article vs. Hibernate EJB3?[ Go to top ]
- Posted by: Dan Greening
- Posted on: December 06 2005 08:52 EST
- in response to Dan Greening
For what it's worth, I meant ".par" not ".ejb3".
QUESTION: Is it true that ".par" is no longer necessary to indicate a persistence archive? (Please.) The presence of a persistence.xml file should be enough to trigger examining annotations, and the extra deployment complexity of dealing with .par using Maven, etc. will hinder adoption. -
Re: Article vs. Hibernate EJB3?[ Go to top ]
- Posted by: Randy Schnier
- Posted on: December 06 2005 11:21 EST
- in response to Dan Greening
QUESTION: Is it true that ".par" is no longer necessary to indicate a persistence archive? (Please.) The presence of a persistence.xml file should be enough to trigger examining annotations, and the extra deployment complexity of dealing with .par using Maven, etc. will hinder adoption.
This is correct. ".par" as a packaging identifier was proposed in one of the earlier versions of the spec, but in the latest spec version, any .jar file containing a persistence.xml file identifies to the EE runtime that the .jar should be examined for entity annotations and xml persistence attributes. (The persistence.xml file identifies which classes within the .jar belong to each Persistence Unit defined for that jar.) In an SE environment, the classes that define the persistence unit are identified to the EntityManager through config parms passed in when the EntityManager is created.
Randy -
Re: Article vs. Hibernate EJB3?[ Go to top ]
- Posted by: Dan Greening
- Posted on: December 06 2005 16:30 EST
- in response to Randy Schnier
QUESTION: Is it true that ".par" is no longer necessary to indicate a persistence archive? (Please.) The presence of a persistence.xml file should be enough to trigger examining annotations, and the extra deployment complexity of dealing with .par using Maven, etc. will hinder adoption.
This is correct. ".par" as a packaging identifier was proposed in one of the earlier versions of the spec, but in the latest spec version, any .jar file containing a persistence.xml file identifies to the EE runtime that the .jar should be examined for entity annotations and xml persistence attributes. (The persistence.xml file identifies which classes within the .jar belong to each Persistence Unit defined for that jar.) In an SE environment, the classes that define the persistence unit are identified to the EntityManager through config parms passed in when the EntityManager is created.Randy
Is this also true for the .ejb3 suffix for Session Beans? Does JBoss support .jar suffix for EJB3 Session Beans? Let me continue this highly moral author trend and say that I declare my undying love to those responsible, if .jar is a fine suffix for EJB3 Session Beans! -
Is .jar enough or do I need .par & .ejb3 etc?[ Go to top ]
- Posted by: Sahoo Sanjeeb
- Posted on: December 07 2005 00:11 EST
- in response to Dan Greening
Is this also true for the .ejb3 suffix for Session Beans?
Yes, it is true for EJB3 session beans as well. It is implemented in glassfish project.
.ejb3 was always a JBoss specific thing, never got into the spec. .par was introduced in the EJB3 spec. But it was subsequently removed.
--Sahoo -
Re: Article vs. Hibernate EJB3?[ Go to top ]
- Posted by: Debu Panda
- Posted on: December 07 2005 16:35 EST
- in response to Dan Greening
Is this also true for the .ejb3 suffix for Session Beans? Does JBoss support .jar suffix for EJB3 Session Beans? Let me continue this highly moral author trend and say that I declare my undying love to those responsible, if .jar is a fine suffix for EJB3 Session Beans!
Oracle supports this in its EJB3 preview since February 2005
http://www.oracle.com/technology/tech/java/ejb30.html
-Debu
http://debupanda.com -
Re: Article vs. Hibernate EJB3?[ Go to top ]
- Posted by: Sahoo Sanjeeb
- Posted on: December 07 2005 21:06 EST
- in response to Dan Greening
Have a look at why .par is not required. Comments welcome.
-- Sahoo -
Article vs. Hibernate EJB3?[ Go to top ]
- Posted by: Sujan J20
- Posted on: December 06 2005 09:22 EST
- in response to Dan Greening
Thank you, Dan. You possess great moral codes to approach authors. Not everyone possesses what you do in this direction.
You illustrated a good method when publishing. I wish, we all illustrate the same (good method) (here on TSS) when posting questions.
Good. -
Article vs. Hibernate EJB3?[ Go to top ]
- Posted by: Matt Giacomini
- Posted on: December 06 2005 13:59 EST
- in response to Sujan J20
Thank you, Dan. You possess great moral codes to approach authors. Not everyone possesses what you do in this direction.You illustrated a good method when publishing. I wish, we all illustrate the same (good method) (here on TSS) when posting questions.Good.
What are you the TTS etiquette cheer learder? -
Article vs. Hibernate EJB3?[ Go to top ]
- Posted by: Emmanuel Bernard
- Posted on: December 06 2005 16:16 EST
- in response to Dan Greening
Some comments online2. Hibernate-EJB3 docs reference a ".ejb3" file which encompasses the persistence unit. Sanjeeb implies this file can be in a simple .jar file. Let me say "massive thank you" to whoever is responsible, if in fact EJB3s can be captured in a simple JAR. The packaging issues for ".ejb3" were going to be pretty annoying.
This is already (and has always been) implemented in Hibernate Entity Manager (ie the simple jar stuff). I should make it clearer from the doc.3. The em.find method was not well documented in Hibernate-EJB3 docs, so it was nice to see it used here.
I don't see much more than UserCredential credential = em.find(UserCredential.class, name); in Sanjeeb article which is more or less the same kind of information that in HEM docs? http://www.hibernate.org/hib_docs/entitymanager/reference/en/html_single/#d0e499
What kind of information were you expecting? Any proposal welcome :-)4. I didn't know that @Id was required, and that it was mentioned in the article saved me some time.
A property(ies) holding the id is required, not @Id (in the last public spec). You can have @Id / @EmbeddedId on a property or even @IdClass at the class level
Emmanuel -
How to enable Java2DB feature in glassfish?[ Go to top ]
- Posted by: Sahoo Sanjeeb
- Posted on: December 05 2005 16:17 EST
- in response to Joseph Ottinger
In my original posting, I mentioned that because of a bug, Java2DB (i.e. automatic table creation during deployment) feature does not work in glassfish for Derby database. Very soon, the bug is going to be fixed. It is right now only working for Oracle database. To enable it, either
1) add a property in persistence.xml under <properties> tag as follows:
<property name="ddl-generation" value="createtables"/>
OR
2) Invoke asadmin deploy command with an additional option -createtables=true. So the complete command is:
$GLASSFISH_HOME/bin/asadmin deploy --user <username> --password <password> --createtables=true <path to jar/war/ear>
Watch out for updates at Persistence RI project page to know when this feature is available for all databases.
--Sahoo -
Java2DB feature now supported for all databases in glassfish[ Go to top ]
- Posted by: Pramod Gopinath
- Posted on: December 06 2005 20:48 EST
- in response to Sahoo Sanjeeb
The bug that Sahoo had mentioned earlier has been resolved. Effective from todays build glassfish would have support for java2db for different databases.