File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Java Products and Servers and the fly likes Java Persistence API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Java Products and Servers
Bookmark "Java Persistence API" Watch "Java Persistence API" New topic

Java Persistence API

Jose Alvarez de Lara
Ranch Hand

Joined: May 10, 2008
Posts: 94


I am developing a web app against glassfish v2ur2 and MySQL 5.0. I am going to use session and entities EJB3 class. And I am having problems to understand the Java Persistence API. I mean:

#1.- Do I need an Entity for any table in the DB?
#2.- On first time I am going to do only select queries, but exists a
relationship type of many-to-many between tables in the DB I solved
with normalization. How do I indicate this relationship in the code?
#3.- I do not use keyGen to generate the PKs. All of them are type of auto-increment.
Is this problematic?
#4.-Do I need an Entity for everyone relation table?

To have you an idea of what I am going to do, it is something like the Duke’s Bank.

Thanks in advance,
Jose Alvarez de Lara

Jose Alvarez de Lara
Ranch Hand

Joined: May 10, 2008
Posts: 94

A fellow explin me the questions, so it let me develop a simple example.
It has two entities, a stateless session as facade and the app client.

Every entity map a table.

Here is the code,

And I get a NullPointerException. Here is the stacktrace,

Any idea?

Best regards,
Jose Alvarez de Lara
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 10032

It seems to me that the DI did not work and the sb reference is null. Could you tell us how you are deploying your application?

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Jose Alvarez de Lara
Ranch Hand

Joined: May 10, 2008
Posts: 94
Thanks for your interesting.

I solved the issue injecting the EJB in a servlet and it worked fine.
So I wanted to go further and develop a web application with three tiers:

#1.- the entities Customer and Order,

#2.- the stateful session ejb CustomerControllerBean and OrderControllerBean that use two JavaBean named CustomerDetails and OrderDetails that represent a Customer and an Order,

#3.- and finally the web tier with some JSPs , a controller Servlet, and two JavaBeans named CustomerBean and OrderBean where I inject the ejb remote interfaces

The idea is to use use the CustomerBean and OrderBean as façade.
Well, as I told you above the firs web application run ok injecting the ejb remote interfaces in the servlet.
But the second and more complicated web application do not works. The problem is the same that you observed in my initial posted application: the injected ejb fails and throw a NullPointerException.

I use Eclipse Ganymede RS1 To develop and deploy the web app on glassfish v2ur2.

Jose Alvarez de Lara
I agree. Here's the link:
subject: Java Persistence API
It's not a secret anymore!